Optimize anki note field generation (#611)
This commit is contained in:
parent
9e6153f172
commit
0c69e54fde
@ -28,8 +28,9 @@ class AnkiNoteBuilder {
|
|||||||
const modeOptions = isKanji ? options.anki.kanji : options.anki.terms;
|
const modeOptions = isKanji ? options.anki.kanji : options.anki.terms;
|
||||||
const modeOptionsFieldEntries = Object.entries(modeOptions.fields);
|
const modeOptionsFieldEntries = Object.entries(modeOptions.fields);
|
||||||
|
|
||||||
|
const fields = {};
|
||||||
const note = {
|
const note = {
|
||||||
fields: {},
|
fields,
|
||||||
tags,
|
tags,
|
||||||
deckName: modeOptions.deck,
|
deckName: modeOptions.deck,
|
||||||
modelName: modeOptions.model,
|
modelName: modeOptions.model,
|
||||||
@ -38,8 +39,17 @@ class AnkiNoteBuilder {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
for (const [fieldName, fieldValue] of modeOptionsFieldEntries) {
|
const formattedFieldValuePromises = [];
|
||||||
note.fields[fieldName] = await this.formatField(fieldValue, definition, mode, context, options, templates, null);
|
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;
|
return note;
|
||||||
|
@ -579,13 +579,14 @@ class Backend {
|
|||||||
const states = [];
|
const states = [];
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const notes = [];
|
const notePromises = [];
|
||||||
for (const definition of definitions) {
|
for (const definition of definitions) {
|
||||||
for (const mode of modes) {
|
for (const mode of modes) {
|
||||||
const note = await this.ankiNoteBuilder.createNote(definition, mode, context, options, templates);
|
const notePromise = this.ankiNoteBuilder.createNote(definition, mode, context, options, templates);
|
||||||
notes.push(note);
|
notePromises.push(notePromise);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
const notes = await Promise.all(notePromises);
|
||||||
|
|
||||||
const cannotAdd = [];
|
const cannotAdd = [];
|
||||||
const results = await this.anki.canAddNotes(notes);
|
const results = await this.anki.canAddNotes(notes);
|
||||||
|
Loading…
Reference in New Issue
Block a user