Fix data not being persisted after terminating Worker thread (#1877)

This commit is contained in:
toasted-nutbread 2021-08-07 15:25:00 -04:00 committed by GitHub
parent e704ae99a2
commit 2d5e6f8394
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 0 deletions

View File

@ -198,6 +198,16 @@ class Database {
});
}
persistData(objectStoreName) {
return new Promise((resolve, reject) => {
const transaction = this.transaction([objectStoreName], 'readonly');
const objectStore = transaction.objectStore(objectStoreName);
const cursor = objectStore.openCursor();
cursor.onerror = (e) => reject(e.target.error);
cursor.onsuccess = () => resolve();
});
}
static deleteDatabase(databaseName) {
return new Promise((resolve, reject) => {
const request = indexedDB.deleteDatabase(databaseName);

View File

@ -317,6 +317,10 @@ class DictionaryDatabase {
return this._db.bulkAdd(objectStoreName, items, start, count);
}
persistData(objectStoreName) {
return this._db.persistData(objectStoreName);
}
// Private
_findMultiBulk(objectStoreName, indexNames, items, createQuery, predicate, createResult) {

View File

@ -149,6 +149,10 @@ class DictionaryImporter {
this._progressData.index += count;
this._progress();
}
// This function is required in order to make the added data persist after the worker is terminated.
// https://bugs.chromium.org/p/chromium/issues/detail?id=1237686
await dictionaryDatabase.persistData(objectStoreName);
};
await bulkAdd('terms', termList);