Better deletion
This commit is contained in:
parent
aab3803786
commit
8b5ee62931
@ -146,7 +146,7 @@ class Database {
|
|||||||
return Promise.reject('database not initialized');
|
return Promise.reject('database not initialized');
|
||||||
}
|
}
|
||||||
|
|
||||||
this.db.dictionaries.where('title').equals(title).first(info => {
|
return this.db.dictionaries.where('title').equals(title).first(info => {
|
||||||
if (!info) {
|
if (!info) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -167,34 +167,42 @@ class Database {
|
|||||||
|
|
||||||
let termDeleter = Promise.resolve();
|
let termDeleter = Promise.resolve();
|
||||||
if (info.hasTerms) {
|
if (info.hasTerms) {
|
||||||
termDeleter = () => {
|
const termDeleterFunc = () => {
|
||||||
this.db.terms.where('dictionary').equals(title).limit(1000).delete(count => {
|
return this.db.terms.where('dictionary').equals(title).limit(1000).delete().then(count => {
|
||||||
if (count > 0) {
|
if (count === 0) {
|
||||||
return termDeleter();
|
return Promise.resolve();
|
||||||
} else {
|
|
||||||
deletedCount += count;
|
|
||||||
if (callback) {
|
|
||||||
callback(deletedCount / totalCount);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
deletedCount += count;
|
||||||
|
if (callback) {
|
||||||
|
callback(totalCount, deletedCount);
|
||||||
|
}
|
||||||
|
|
||||||
|
return termDeleterFunc();
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
termDeleter = termDeleterFunc();
|
||||||
}
|
}
|
||||||
|
|
||||||
let kanjiDeleter = Promise.resolve();
|
let kanjiDeleter = Promise.resolve();
|
||||||
if (info.hasKanji) {
|
if (info.hasKanji) {
|
||||||
kanjiDeleter = () => {
|
const kanjiDeleterFunc = () => {
|
||||||
this.db.terms.where('dictionary').equals(title).limit(1000).delete(count => {
|
return this.db.kanji.where('dictionary').equals(title).limit(1000).delete().then(count => {
|
||||||
if (count > 0) {
|
if (count === 0) {
|
||||||
return kanjiDeleter();
|
return Promise.resolve();
|
||||||
} else {
|
|
||||||
deletedCount += count;
|
|
||||||
if (callback) {
|
|
||||||
callback(deletedCount / totalCount);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
deletedCount += count;
|
||||||
|
if (callback) {
|
||||||
|
callback(totalCount, deletedCount);
|
||||||
|
}
|
||||||
|
|
||||||
|
return kanjiDeleterFunc();
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
kanjiDeleter = kanjiDeleterFunc();
|
||||||
}
|
}
|
||||||
|
|
||||||
return Promise.all([termDeleter, kanjiDeleter]);
|
return Promise.all([termDeleter, kanjiDeleter]);
|
||||||
|
@ -164,7 +164,11 @@ function onDictionaryDelete() {
|
|||||||
const dictControls = dictGroup.find('.dict-controls');
|
const dictControls = dictGroup.find('.dict-controls');
|
||||||
dictControls.hide();
|
dictControls.hide();
|
||||||
|
|
||||||
database().deleteDictionary(dictGroup.data('title')).then(() => {
|
const callback = (total, current) => {
|
||||||
|
dictProgress.find('div').css('width', `${current / total * 100.0}%`);
|
||||||
|
};
|
||||||
|
|
||||||
|
database().deleteDictionary(dictGroup.data('title'), callback).then(() => {
|
||||||
dictGroup.slideUp();
|
dictGroup.slideUp();
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
dictError.show().find('span').text(error);
|
dictError.show().find('span').text(error);
|
||||||
|
Loading…
Reference in New Issue
Block a user