Merge pull request #77 from lae/fix/async-bulk-import-failure

Import terms/kanji with transactional adds instead of bulkAdd on async
This commit is contained in:
Alex Yatskov 2017-09-11 21:56:35 -07:00 committed by GitHub
commit a0d8e9d81b

View File

@ -187,20 +187,19 @@ class Database {
callback(total, current); callback(total, current);
} }
const rows = []; await this.db.transaction('rw', this.db.terms, async function() {
for (const [expression, reading, tags, rules, score, ...glossary] of entries) { for (const [expression, reading, tags, rules, score, ...glossary] of entries) {
rows.push({ this.db.terms.add({
expression, expression,
reading, reading,
tags, tags,
rules, rules,
score, score,
glossary, glossary,
dictionary: title dictionary: title
}); });
} }
});
await this.db.terms.bulkAdd(rows);
}; };
const kanjiLoaded = async (title, entries, total, current) => { const kanjiLoaded = async (title, entries, total, current) => {
@ -208,19 +207,18 @@ class Database {
callback(total, current); callback(total, current);
} }
const rows = []; await this.db.transaction('rw', this.db.kanji, async function() {
for (const [character, onyomi, kunyomi, tags, ...meanings] of entries) { for (const [character, onyomi, kunyomi, tags, ...meanings] of entries) {
rows.push({ this.db.kanji.add({
character, character,
onyomi, onyomi,
kunyomi, kunyomi,
tags, tags,
meanings, meanings,
dictionary: title dictionary: title
}); });
} }
});
await this.db.kanji.bulkAdd(rows);
}; };
await Database.importDictionaryZip(archive, indexLoaded, termsLoaded, kanjiLoaded); await Database.importDictionaryZip(archive, indexLoaded, termsLoaded, kanjiLoaded);