From 365843ea76e9c47921bf6530ce1ed89657883057 Mon Sep 17 00:00:00 2001 From: Jason Williams <936006+jasonwilliams@users.noreply.github.com> Date: Sun, 30 Jun 2024 15:18:26 +0100 Subject: [PATCH] run updates to cards in sequence to not overload ankiConnect connections (#132) --- package-lock.json | 4 ++-- package.json | 2 +- src/models/Deck.ts | 11 +++++++---- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/package-lock.json b/package-lock.json index eea3772..4619f9c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "anki", - "version": "1.3.2", + "version": "1.3.4", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "anki", - "version": "1.3.2", + "version": "1.3.4", "license": "MIT", "dependencies": { "cheerio": "^1.0.0-rc.10", diff --git a/package.json b/package.json index 802e04b..f2c0b68 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "anki", "displayName": "Anki for VSCode", "description": "Sync notes with your locally running Anki", - "version": "1.3.3", + "version": "1.3.4", "publisher": "jasew", "license": "MIT", "engines": { diff --git a/src/models/Deck.ts b/src/models/Deck.ts index e8cb6c2..1e44c58 100644 --- a/src/models/Deck.ts +++ b/src/models/Deck.ts @@ -1,7 +1,7 @@ -import { Card } from "./Card"; +import { workspace } from "vscode"; import { AnkiService } from "../AnkiService"; +import { Card } from "./Card"; import { SendDiff } from "./SendDiff"; -import { workspace } from "vscode"; export class Deck { public readonly name: string; @@ -112,8 +112,11 @@ export class Deck { } // Calls anki to update the fields of all the passed cards. - private async _pushUpdatedCardsToAnki(cards: Card[]): Promise { - return Promise.all(cards.map((card) => this.ankiService?.updateFields(card))); + private async _pushUpdatedCardsToAnki(cards: Card[]): Promise { + // This should be in sequence to not overload AnkiConnect's connection limit + for (const card of cards) { + await this.ankiService?.updateFields(card); + } } async createAndUpdateCards(): Promise {