diff options
author | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2021-03-14 22:51:20 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-14 22:51:20 -0400 |
commit | a52d86a39e9cca620823e3d97d7c129a7abafced (patch) | |
tree | 1e75aef621f21a96a21bdff14ad2e48056ec56d2 /ext/js/language/translator.js | |
parent | 07df1e011794f5a77f7fb7da5cd9ea353a8747e2 (diff) |
Dictionary database improvements (#1527)
* Update formatting
* Add _findMultiBulk
* Update implementation of findTermsBySequenceBulk
* Update tests
* Generalize query creation
* Remove _findGenericBulk
* Reduce function creation
* Add more bindings
* Simplify findTermsExactBulk implementation
* Update var names
* Update _findMultiBulk to support multiple index queries
* Update findTermsBulk
* Update getMedia implementation
* Pass data arg to getAll and findFirst to avoid having multiple closures
Diffstat (limited to 'ext/js/language/translator.js')
-rw-r--r-- | ext/js/language/translator.js | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/ext/js/language/translator.js b/ext/js/language/translator.js index 761fac6b..151b1172 100644 --- a/ext/js/language/translator.js +++ b/ext/js/language/translator.js @@ -392,7 +392,8 @@ class Translator { } async _addRelatedDefinitions(sequencedDefinitions, unsequencedDefinitions, sequenceList, mainDictionary, enabledDictionaryMap) { - const databaseDefinitions = await this._database.findTermsBySequenceBulk(sequenceList, mainDictionary); + const items = sequenceList.map((query) => ({query, dictionary: mainDictionary})); + const databaseDefinitions = await this._database.findTermsBySequenceBulk(items); for (const databaseDefinition of databaseDefinitions) { const {relatedDefinitions, definitionIds} = sequencedDefinitions[databaseDefinition.index]; const {id} = databaseDefinition; @@ -410,8 +411,7 @@ class Translator { if (unsequencedDefinitions.length === 0 && secondarySearchDictionaryMap.size === 0) { return; } // Prepare grouping info - const expressionList = []; - const readingList = []; + const termList = []; const targetList = []; const targetMap = new Map(); @@ -431,8 +431,7 @@ class Translator { target.sequencedDefinitions.push(sequencedDefinition); if (!definition.isPrimary && !target.searchSecondary) { target.searchSecondary = true; - expressionList.push(expression); - readingList.push(reading); + termList.push({expression, reading}); targetList.push(target); } } @@ -456,14 +455,14 @@ class Translator { } // Search database for additional secondary terms - if (expressionList.length === 0 || secondarySearchDictionaryMap.size === 0) { return; } + if (termList.length === 0 || secondarySearchDictionaryMap.size === 0) { return; } - const databaseDefinitions = await this._database.findTermsExactBulk(expressionList, readingList, secondarySearchDictionaryMap); + const databaseDefinitions = await this._database.findTermsExactBulk(termList, secondarySearchDictionaryMap); this._sortDatabaseDefinitionsByIndex(databaseDefinitions); for (const databaseDefinition of databaseDefinitions) { const {index, id} = databaseDefinition; - const source = expressionList[index]; + const source = termList[index].expression; const target = targetList[index]; for (const {definitionIds, secondaryDefinitions} of target.sequencedDefinitions) { if (definitionIds.has(id)) { continue; } |