summaryrefslogtreecommitdiff
path: root/ext/bg/js/database.js
diff options
context:
space:
mode:
authorAlex Yatskov <alex@foosoft.net>2016-11-10 19:36:45 -0800
committerAlex Yatskov <alex@foosoft.net>2016-11-10 19:36:45 -0800
commit0ff41d5843b3bf39994ae32e4ab623bfe0e4e3ca (patch)
treeb1eb44335b0004c9e5243db8db5ed90b4a52a942 /ext/bg/js/database.js
parent8b5ee629311065bc53537d5684931dbf775c4e3e (diff)
Delete dictionary deletion
Diffstat (limited to 'ext/bg/js/database.js')
-rw-r--r--ext/bg/js/database.js73
1 files changed, 0 insertions, 73 deletions
diff --git a/ext/bg/js/database.js b/ext/bg/js/database.js
index e3a62886..24ee7c03 100644
--- a/ext/bg/js/database.js
+++ b/ext/bg/js/database.js
@@ -141,79 +141,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 totalCount = termCount + kanjiCount;
- let deletedCount = 0;
-
- let termDeleter = Promise.resolve();
- if (info.hasTerms) {
- const termDeleterFunc = () => {
- return this.db.terms.where('dictionary').equals(title).limit(1000).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(1000).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.entities.where('dictionary').equals(title).delete();
- }).then(() => {
- return this.db.dictionaries.where('title').equals(title).delete();
- });
- }
-
importDictionary(indexUrl, callback) {
if (this.db === null) {
return Promise.reject('database not initialized');