From 8233119eb7b15099da310dbd46f005ee678e42ca Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Fri, 24 Jan 2020 22:24:05 -0500 Subject: [PATCH] Update how frequency data is set up --- ext/bg/js/translator.js | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/ext/bg/js/translator.js b/ext/bg/js/translator.js index e5e34ed8..ebb02687 100644 --- a/ext/bg/js/translator.js +++ b/ext/bg/js/translator.js @@ -424,13 +424,13 @@ class Translator { definition.frequencies = []; } - for (const meta of await this.database.findKanjiMetaBulk(kanjiList2, titles)) { - if (meta.mode !== 'freq') { continue; } - definitions[meta.index].frequencies.push({ - character: meta.character, - frequency: meta.data, - dictionary: meta.dictionary - }); + const metas = await this.database.findKanjiMetaBulk(kanjiList2, titles); + for (const {character, mode, data, dictionary, index} of metas) { + switch (mode) { + case 'freq': + definitions[index].frequencies.push({character, frequency: data, dictionary}); + break; + } } return definitions; @@ -471,17 +471,13 @@ class Translator { } const metas = await this.database.findTermMetaBulk(expressionsUnique, titles); - for (const meta of metas) { - if (meta.mode !== 'freq') { - continue; - } - - for (const term of termsUnique[meta.index]) { - term.frequencies.push({ - expression: meta.expression, - frequency: meta.data, - dictionary: meta.dictionary - }); + for (const {expression, mode, data, dictionary, index} of metas) { + switch (mode) { + case 'freq': + for (const term of termsUnique[index]) { + term.frequencies.push({expression, frequency: data, dictionary}); + } + break; } } }