diff options
author | siikamiika <siikamiika@users.noreply.github.com> | 2017-10-24 13:45:51 +0300 |
---|---|---|
committer | siikamiika <siikamiika@users.noreply.github.com> | 2017-10-24 13:45:51 +0300 |
commit | df0d2beb735c75948feccd64398e6187c61c2fde (patch) | |
tree | 2c4af7e34517088e660793554c67a0d5c45b7e77 | |
parent | 8400f0e4c0d0dc8253fbf1efcd7459c218a6886c (diff) |
database.js: add hasSequences
-rw-r--r-- | ext/bg/js/database.js | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/ext/bg/js/database.js b/ext/bg/js/database.js index 469b1311..9e90e6de 100644 --- a/ext/bg/js/database.js +++ b/ext/bg/js/database.js @@ -233,7 +233,7 @@ class Database { throw 'Database not initialized'; } - const indexDataLoaded = async summary => { + const indexDataValid = async summary => { if (summary.version > 2) { throw 'Unsupported dictionary version'; } @@ -242,7 +242,9 @@ class Database { if (count > 0) { throw 'Dictionary is already imported'; } + }; + const indexDataLoaded = async summary => { await this.db.dictionaries.add(summary); }; @@ -280,6 +282,8 @@ class Database { } } + summary.hasSequences = rows.every(row => row.sequence >= 0); + await this.db.terms.bulkAdd(rows); }; @@ -377,6 +381,7 @@ class Database { return await Database.importDictionaryZip( archive, + indexDataValid, indexDataLoaded, termDataLoaded, termMetaDataLoaded, @@ -388,6 +393,7 @@ class Database { static async importDictionaryZip( archive, + indexDataValid, indexDataLoaded, termDataLoaded, termMetaDataLoaded, @@ -413,9 +419,7 @@ class Database { version: index.format || index.version }; - if (indexDataLoaded) { - await indexDataLoaded(summary); - } + await indexDataValid(summary); const buildTermBankName = index => `term_bank_${index + 1}.json`; const buildTermMetaBankName = index => `term_meta_bank_${index + 1}.json`; @@ -472,6 +476,10 @@ class Database { await loadBank(summary, buildKanjiMetaBankName, kanjiMetaBankCount, kanjiMetaDataLoaded); await loadBank(summary, buildTagBankName, tagBankCount, tagDataLoaded); + if (indexDataLoaded) { + await indexDataLoaded(summary); + } + return summary; } } |