aboutsummaryrefslogtreecommitdiff
path: root/ext/bg/js
diff options
context:
space:
mode:
Diffstat (limited to 'ext/bg/js')
-rw-r--r--ext/bg/js/anki-note-builder.js16
-rw-r--r--ext/bg/js/backend.js7
2 files changed, 17 insertions, 6 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;
diff --git a/ext/bg/js/backend.js b/ext/bg/js/backend.js
index 93ba620f..a8ee9f83 100644
--- a/ext/bg/js/backend.js
+++ b/ext/bg/js/backend.js
@@ -579,13 +579,14 @@ class Backend {
const states = [];
try {
- const notes = [];
+ const notePromises = [];
for (const definition of definitions) {
for (const mode of modes) {
- const note = await this.ankiNoteBuilder.createNote(definition, mode, context, options, templates);
- notes.push(note);
+ const notePromise = this.ankiNoteBuilder.createNote(definition, mode, context, options, templates);
+ notePromises.push(notePromise);
}
}
+ const notes = await Promise.all(notePromises);
const cannotAdd = [];
const results = await this.anki.canAddNotes(notes);