aboutsummaryrefslogtreecommitdiff
path: root/ext/bg/js/anki-note-builder.js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2020-06-21 15:54:34 -0400
committerGitHub <noreply@github.com>2020-06-21 15:54:34 -0400
commit0c69e54fde259568ebd89a3c9e8481cf28860ea8 (patch)
treea472ac24e87a3718d80cb4a9903f74357d804e28 /ext/bg/js/anki-note-builder.js
parent9e6153f172fd9043eaa34cd2de639ce2b9c3f4a3 (diff)
Optimize anki note field generation (#611)
Diffstat (limited to 'ext/bg/js/anki-note-builder.js')
-rw-r--r--ext/bg/js/anki-note-builder.js16
1 files changed, 13 insertions, 3 deletions
diff --git a/ext/bg/js/anki-note-builder.js b/ext/bg/js/anki-note-builder.js
index 31e67394..7fe8962a 100644
--- a/ext/bg/js/anki-note-builder.js
+++ b/ext/bg/js/anki-note-builder.js
@@ -28,8 +28,9 @@ class AnkiNoteBuilder {
const modeOptions = isKanji ? options.anki.kanji : options.anki.terms;
const modeOptionsFieldEntries = Object.entries(modeOptions.fields);
+ const fields = {};
const note = {
- fields: {},
+ fields,
tags,
deckName: modeOptions.deck,
modelName: modeOptions.model,
@@ -38,8 +39,17 @@ class AnkiNoteBuilder {
}
};
- for (const [fieldName, fieldValue] of modeOptionsFieldEntries) {
- note.fields[fieldName] = await this.formatField(fieldValue, definition, mode, context, options, templates, null);
+ const formattedFieldValuePromises = [];
+ for (const [, fieldValue] of modeOptionsFieldEntries) {
+ const formattedFieldValuePromise = this.formatField(fieldValue, definition, mode, context, options, templates, null);
+ formattedFieldValuePromises.push(formattedFieldValuePromise);
+ }
+
+ const formattedFieldValues = await Promise.all(formattedFieldValuePromises);
+ for (let i = 0, ii = modeOptionsFieldEntries.length; i < ii; ++i) {
+ const fieldName = modeOptionsFieldEntries[i][0];
+ const formattedFieldValue = formattedFieldValues[i];
+ fields[fieldName] = formattedFieldValue;
}
return note;