summaryrefslogtreecommitdiff
path: root/ext/bg/js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2019-11-03 13:41:32 -0500
committertoasted-nutbread <toasted-nutbread@users.noreply.github.com>2019-11-10 13:01:39 -0500
commit6c023789d93e9799370dc496f9d35d8cdf66be38 (patch)
treec2b73644cea2920025129c434311fc680c32b379 /ext/bg/js
parent750439ebf05768c66d8aec85993f711f97562b60 (diff)
Use native IndexedDB for bulkAdd operations
Diffstat (limited to 'ext/bg/js')
-rw-r--r--ext/bg/js/database.js39
1 files changed, 13 insertions, 26 deletions
diff --git a/ext/bg/js/database.js b/ext/bg/js/database.js
index ab23ce2b..e5245582 100644
--- a/ext/bg/js/database.js
+++ b/ext/bg/js/database.js
@@ -292,14 +292,18 @@ class Database {
this.validate();
const maxTransactionLength = 1000;
- const bulkAdd = async (table, items, total, current) => {
- if (items.length < maxTransactionLength) {
+ const bulkAdd = async (objectStoreName, items, total, current) => {
+ const db = this.db.backendDB();
+ for (let i = 0; i < items.length; i += maxTransactionLength) {
if (progressCallback) {
- progressCallback(total, current);
+ progressCallback(total, current + i / items.length);
}
try {
- await table.bulkAdd(items);
+ const count = Math.min(maxTransactionLength, items.length - i);
+ const transaction = db.transaction([objectStoreName], 'readwrite');
+ const objectStore = transaction.objectStore(objectStoreName);
+ await Database.bulkAdd(objectStore, items, i, count);
} catch (e) {
if (exceptions) {
exceptions.push(e);
@@ -307,23 +311,6 @@ class Database {
throw e;
}
}
- } else {
- for (let i = 0; i < items.length; i += maxTransactionLength) {
- if (progressCallback) {
- progressCallback(total, current + i / items.length);
- }
-
- let count = Math.min(maxTransactionLength, items.length - i);
- try {
- await table.bulkAdd(items.slice(i, i + count));
- } catch (e) {
- if (exceptions) {
- exceptions.push(e);
- } else {
- throw e;
- }
- }
- }
}
};
@@ -377,7 +364,7 @@ class Database {
}
}
- await bulkAdd(this.db.terms, rows, total, current);
+ await bulkAdd('terms', rows, total, current);
};
const termMetaDataLoaded = async (summary, entries, total, current) => {
@@ -391,7 +378,7 @@ class Database {
});
}
- await bulkAdd(this.db.termMeta, rows, total, current);
+ await bulkAdd('termMeta', rows, total, current);
};
const kanjiDataLoaded = async (summary, entries, total, current) => {
@@ -421,7 +408,7 @@ class Database {
}
}
- await bulkAdd(this.db.kanji, rows, total, current);
+ await bulkAdd('kanji', rows, total, current);
};
const kanjiMetaDataLoaded = async (summary, entries, total, current) => {
@@ -435,7 +422,7 @@ class Database {
});
}
- await bulkAdd(this.db.kanjiMeta, rows, total, current);
+ await bulkAdd('kanjiMeta', rows, total, current);
};
const tagDataLoaded = async (summary, entries, total, current) => {
@@ -453,7 +440,7 @@ class Database {
rows.push(row);
}
- await bulkAdd(this.db.tagMeta, rows, total, current);
+ await bulkAdd('tagMeta', rows, total, current);
};
return await Database.importDictionaryZip(