Wait for IndexedDB transactions to complete for import scale (#1698)

* No longer reference 'Chrome App' on the start screen

* Imports are only complete when IndexedDB transaction is complete
pull/749/head
Scott Nonnenberg 8 years ago committed by GitHub
parent 9a181ef4e9
commit 845291c51e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -499,7 +499,7 @@
"description": "One of two choices presented on the screen shown on first launch" "description": "One of two choices presented on the screen shown on first launch"
}, },
"installImport": { "installImport": {
"message": "Set up with Chrome App export", "message": "Set up with exported data",
"description": "One of two choices presented on the screen shown on first launch" "description": "One of two choices presented on the screen shown on first launch"
}, },
"installGetStartedButton": { "installGetStartedButton": {

@ -178,8 +178,18 @@
console.log('Importing to these stores:', storeNames.join(', ')); console.log('Importing to these stores:', storeNames.join(', '));
var finished = false;
var finish = function(via) {
console.log('non-messages import done via', via);
if (finished) {
resolve();
}
finished = true;
};
var transaction = idb_db.transaction(storeNames, 'readwrite'); var transaction = idb_db.transaction(storeNames, 'readwrite');
transaction.onerror = reject; transaction.onerror = reject;
transaction.oncomplete = finish.bind(null, 'transaction complete');
_.each(storeNames, function(storeName) { _.each(storeNames, function(storeName) {
console.log('Importing items for store', storeName); console.log('Importing items for store', storeName);
@ -202,7 +212,7 @@
if (_.keys(importObject).length === 0) { if (_.keys(importObject).length === 0) {
// added all object stores // added all object stores
console.log('DB import complete'); console.log('DB import complete');
resolve(); finish('puts scheduled');
} }
} }
}; };
@ -581,6 +591,15 @@
} }
return new Promise(function(resolve, reject) { return new Promise(function(resolve, reject) {
var finished = false;
var finish = function(via) {
console.log('messages done saving via', via);
if (finished) {
resolve();
}
finished = true;
};
var transaction = idb_db.transaction('messages', 'readwrite'); var transaction = idb_db.transaction('messages', 'readwrite');
transaction.onerror = function(e) { transaction.onerror = function(e) {
console.log( console.log(
@ -589,6 +608,7 @@
); );
return reject(e); return reject(e);
}; };
transaction.oncomplete = finish.bind(null, 'transaction complete');
var store = transaction.objectStore('messages'); var store = transaction.objectStore('messages');
var conversationId = messages[0].conversationId; var conversationId = messages[0].conversationId;
@ -606,7 +626,7 @@
// Don't know if group or private conversation, so we blindly redact // Don't know if group or private conversation, so we blindly redact
'[REDACTED]' + conversationId.slice(-3) '[REDACTED]' + conversationId.slice(-3)
); );
resolve(); finish('puts scheduled');
} }
}; };
request.onerror = function(event) { request.onerror = function(event) {

Loading…
Cancel
Save