summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Yatskov <FooSoft@users.noreply.github.com>2017-09-11 21:56:35 -0700
committerGitHub <noreply@github.com>2017-09-11 21:56:35 -0700
commita0d8e9d81b5f0da690daea2a4e0a8b2667946c1a (patch)
treea59c54432d26760af4655c995066aa5f80caaa97
parent2eb85cb835a4aece7839eba25c0030e9eb186f85 (diff)
parentaea55b348f6c0f1511b8fb1e98f48b5126c8eff8 (diff)
Merge pull request #77 from lae/fix/async-bulk-import-failure
Import terms/kanji with transactional adds instead of bulkAdd on async
-rw-r--r--ext/bg/js/database.js52
1 files changed, 25 insertions, 27 deletions
diff --git a/ext/bg/js/database.js b/ext/bg/js/database.js
index e00cb7a3..65fc78fb 100644
--- a/ext/bg/js/database.js
+++ b/ext/bg/js/database.js
@@ -187,20 +187,19 @@ class Database {
callback(total, current);
}
- const rows = [];
- for (const [expression, reading, tags, rules, score, ...glossary] of entries) {
- rows.push({
- expression,
- reading,
- tags,
- rules,
- score,
- glossary,
- dictionary: title
- });
- }
-
- await this.db.terms.bulkAdd(rows);
+ await this.db.transaction('rw', this.db.terms, async function() {
+ for (const [expression, reading, tags, rules, score, ...glossary] of entries) {
+ this.db.terms.add({
+ expression,
+ reading,
+ tags,
+ rules,
+ score,
+ glossary,
+ dictionary: title
+ });
+ }
+ });
};
const kanjiLoaded = async (title, entries, total, current) => {
@@ -208,19 +207,18 @@ class Database {
callback(total, current);
}
- const rows = [];
- for (const [character, onyomi, kunyomi, tags, ...meanings] of entries) {
- rows.push({
- character,
- onyomi,
- kunyomi,
- tags,
- meanings,
- dictionary: title
- });
- }
-
- await this.db.kanji.bulkAdd(rows);
+ await this.db.transaction('rw', this.db.kanji, async function() {
+ for (const [character, onyomi, kunyomi, tags, ...meanings] of entries) {
+ this.db.kanji.add({
+ character,
+ onyomi,
+ kunyomi,
+ tags,
+ meanings,
+ dictionary: title
+ });
+ }
+ });
};
await Database.importDictionaryZip(archive, indexLoaded, termsLoaded, kanjiLoaded);