Skip to content

Messaging - IDB Cleanup #523

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Feb 21, 2018
Merged

Messaging - IDB Cleanup #523

merged 4 commits into from
Feb 21, 2018

Conversation

gauntface
Copy link

A few bugs have been highlighted from 4.9x => 4.10.0:

  • There was a bug in <= 4.9.X builds of the messaging SDK that meant the SDK was using an IDB name of 'undefined'. My hunch is something went wonky in closure -> typescript.
  • If the name wasn't undefined the changes in 4.10 should have been fine, but because there is now a difference IDB name, the SDK is creating a new token, meaning end users can get two notifications - one for the old token and one for the new token.

This PR will bump the version of the IDB database in the next release, and clean up any old IDB instances if they exist in the version upgrade step.

@gauntface gauntface changed the title Goes through and deletes old IDB entries Messaging - IDB Feb 20, 2018
@gauntface gauntface changed the title Messaging - IDB Messaging - IDB Cleanup Feb 20, 2018
@gauntface gauntface requested a review from jshcrowthe February 20, 2018 20:36
@gauntface
Copy link
Author

@jshcrowthe I can't add @pinarx as a reviewer to this PR for some reason.

return 'fcm_token_details_db';
}
onDBUpgrade(db: IDBDatabase, evt: IDBVersionChangeEvent) {
if (evt.oldVersion < 1) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this means it's brand new, right? can you add a quick comment?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added comment

if (!db.objectStoreNames.contains(OLD_OBJECT_STORE_NAME)) {
// We found a database with the right name, but our expected object
// store isn't defined.
return;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this comment is confusing. So the v1 object store doesn't exist, and the new one is not defined yet? does this imply the old object store was dropped (maybe manually), and a new one isn't created yet?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is looking for the database named 'undefined', which could be used be created anyone, which if it is - we perhaps may not be the owner and therefore the expected object store wouldnt exist.

return;
}

const transaction = db.transaction([OLD_OBJECT_STORE_NAME]);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can probably drop the brackets:

the following lines are equivalent:
var transaction = db.transaction(['my-store-name']);
var transaction = db.transaction('my-store-name');

import IIDModel from '../models/iid-model';

const OLD_DB_NAME = 'undefined';
const OLD_OBJECT_STORE_NAME = 'fcm_token_object_Store';
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OBJECT_STORE_NAME_V1 and DB_NAME_V1?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code is purely cleaning up the old model (which shouldn't have been named 'undefined' but it was). So this, while related to the token-details-model, they are separate databases and I am just using the v1 -> v2 change to perform this one off clean up. So the version shouldn't every be included or needed here.


const openCursorRequest: IDBRequest = objectStore.openCursor();
openCursorRequest.onerror = event => {
// NOOP - Nothing we can do.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would it be helpful to log something to the console?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a warning log.

} else {
// No more results - delete database if we are the only
// SDK using it
if (db.objectStoreNames.length === 1) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we just check if the name matches in that case? rather than checking the length?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clear the database.

@firebase firebase deleted a comment from pinarx Feb 20, 2018
@firebase firebase deleted a comment from pinarx Feb 20, 2018
Copy link
Contributor

@jshcrowthe jshcrowthe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM thanks @gauntface

@jshcrowthe jshcrowthe merged commit dbe5fff into master Feb 21, 2018
@jshcrowthe jshcrowthe deleted the messaging-idb-fix branch February 21, 2018 00:16
@CTassisF
Copy link

Is it intentional that after this PR firebase.js is creating a new, empty IDB named "undefined" even when it doesn't exist, like when a new visitor comes or firebase.js 4.10.1 is deployed for the first time in a website?

@firebase firebase locked and limited conversation to collaborators Oct 22, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants