-
Notifications
You must be signed in to change notification settings - Fork 940
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
Conversation
@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) { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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]); |
There was a problem hiding this comment.
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'; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Clear the database.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM thanks @gauntface
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? |
A few bugs have been highlighted from 4.9x => 4.10.0:
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.