diff options
author | Alex Yatskov <alex@foosoft.net> | 2017-02-26 10:11:23 -0800 |
---|---|---|
committer | Alex Yatskov <alex@foosoft.net> | 2017-02-26 10:11:23 -0800 |
commit | 55dd9b1e6b06401e5a5f523fce1f3d6c1db4d9da (patch) | |
tree | 6895213af2f287bc317daa24516dc54c3f1cc0f1 /ext/bg/js/database.js | |
parent | 465a8e21c0a9d7b2d1e704ab9a42b5f662fd82d3 (diff) |
delete unused dictionary deletion code
Diffstat (limited to 'ext/bg/js/database.js')
-rw-r--r-- | ext/bg/js/database.js | 78 |
1 files changed, 1 insertions, 77 deletions
diff --git a/ext/bg/js/database.js b/ext/bg/js/database.js index 7dc533e3..31573065 100644 --- a/ext/bg/js/database.js +++ b/ext/bg/js/database.js @@ -45,7 +45,7 @@ class Database { terms: '++id,dictionary,expression,reading', kanji: '++,dictionary,character', tagMeta: '++,dictionary', - dictionaries: '++,title,version', + dictionaries: '++,title,version' }); return this.db.open(); @@ -155,82 +155,6 @@ class Database { return this.db.dictionaries.toArray(); } - deleteDictionary(title, callback) { - if (this.db === null) { - return Promise.reject('database not initialized'); - } - - return this.db.dictionaries.where('title').equals(title).first(info => { - if (!info) { - return; - } - - let termCounter = Promise.resolve(0); - if (info.hasTerms) { - termCounter = this.db.terms.where('dictionary').equals(title).count(); - } - - let kanjiCounter = Promise.resolve(0); - if (info.hasKanji) { - kanjiCounter = this.db.kanji.where('dictionary').equals(title).count(); - } - - return Promise.all([termCounter, kanjiCounter]).then(([termCount, kanjiCount]) => { - const rowLimit = 500; - const totalCount = termCount + kanjiCount; - let deletedCount = 0; - - let termDeleter = Promise.resolve(); - if (info.hasTerms) { - const termDeleterFunc = () => { - return this.db.terms.where('dictionary').equals(title).limit(rowLimit).delete().then(count => { - if (count === 0) { - return Promise.resolve(); - } - - deletedCount += count; - if (callback) { - callback(totalCount, deletedCount); - } - - return termDeleterFunc(); - }); - }; - - termDeleter = termDeleterFunc(); - } - - let kanjiDeleter = Promise.resolve(); - if (info.hasKanji) { - const kanjiDeleterFunc = () => { - return this.db.kanji.where('dictionary').equals(title).limit(rowLimit).delete().then(count => { - if (count === 0) { - return Promise.resolve(); - } - - deletedCount += count; - if (callback) { - callback(totalCount, deletedCount); - } - - return kanjiDeleterFunc(); - }); - }; - - kanjiDeleter = kanjiDeleterFunc(); - } - - return Promise.all([termDeleter, kanjiDeleter]); - }); - }).then(() => { - return this.db.tagMeta.where('dictionary').equals(title).delete(); - }).then(() => { - return this.db.dictionaries.where('title').equals(title).delete(); - }).then(() => { - delete this.cacheTagMeta[title]; - }); - } - importDictionary(indexUrl, callback) { if (this.db === null) { return Promise.reject('database not initialized'); |