From c62cc01642b29c13a38f3bcc08f2fa144107c158 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Sun, 29 Oct 2017 10:42:39 -0700 Subject: simplify database interface --- ext/bg/js/database.js | 17 +---------------- ext/bg/js/settings.js | 14 +++++++------- ext/bg/js/util.js | 12 ++++-------- 3 files changed, 12 insertions(+), 31 deletions(-) diff --git a/ext/bg/js/database.js b/ext/bg/js/database.js index fcf8ef3f..14b3243a 100644 --- a/ext/bg/js/database.js +++ b/ext/bg/js/database.js @@ -220,7 +220,7 @@ class Database { return result; } - async getTitles() { + async summarize() { if (this.db) { return this.db.dictionaries.toArray(); } else { @@ -228,21 +228,6 @@ class Database { } } - async getTitlesWithSequences() { - if (!this.db) { - throw 'Database not initialized'; - } - - const titles = []; - await this.db.dictionaries.each(row => { - if (row.hasSequences) { - titles.push(row.title); - } - }); - - return titles; - } - async importDictionary(archive, callback) { if (!this.db) { throw 'Database not initialized'; diff --git a/ext/bg/js/settings.js b/ext/bg/js/settings.js index d608a81b..9d47f33c 100644 --- a/ext/bg/js/settings.js +++ b/ext/bg/js/settings.js @@ -109,12 +109,12 @@ async function formMainDictionaryOptionsPopulate(options) { select.append($('')); let mainDictionary = ''; - const formOptions = [$]; - const titles = await utilDatabaseGetTitlesWithSequences(); - for (const title of titles) { - select.append($(``)); - if (title === options.general.mainDictionary) { - mainDictionary = title; + for (const dictRow of await utilDatabaseSummarize()) { + if (dictRow.hasSequences) { + select.append($(``)); + if (dictRow.title === options.general.mainDictionary) { + mainDictionary = dictRow.title; + } } } @@ -271,7 +271,7 @@ async function dictionaryGroupsPopulate(options) { const dictGroups = $('#dict-groups').empty(); const dictWarning = $('#dict-warning').hide(); - const dictRows = await utilDatabaseGetTitles(); + const dictRows = await utilDatabaseSummarize(); if (dictRows.length === 0) { dictWarning.show(); } diff --git a/ext/bg/js/util.js b/ext/bg/js/util.js index 091137ed..216cef3f 100644 --- a/ext/bg/js/util.js +++ b/ext/bg/js/util.js @@ -75,16 +75,12 @@ function utilAnkiGetDeckNames() { return utilBackend().anki.getDeckNames(); } -function utilAnkiGetModelFieldNames(modelName) { - return utilBackend().anki.getModelFieldNames(modelName); -} - -function utilDatabaseGetTitles() { - return utilBackend().translator.database.getTitles(); +function utilDatabaseSummarize() { + return utilBackend().translator.database.summarize(); } -function utilDatabaseGetTitlesWithSequences() { - return utilBackend().translator.database.getTitlesWithSequences(); +function utilAnkiGetModelFieldNames(modelName) { + return utilBackend().anki.getModelFieldNames(modelName); } function utilDatabasePurge() { -- cgit v1.2.3