Skip to content

Commit

Permalink
run updates to cards in sequence to not overload ankiConnect connections
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonwilliams committed Jun 30, 2024
1 parent 2eebaff commit 6a89555
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
11 changes: 7 additions & 4 deletions src/models/Deck.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -112,8 +112,11 @@ export class Deck {
}

// Calls anki to update the fields of all the passed cards.
private async _pushUpdatedCardsToAnki(cards: Card[]): Promise<Card[]> {
return Promise.all(cards.map((card) => this.ankiService?.updateFields(card)));
private async _pushUpdatedCardsToAnki(cards: Card[]): Promise<void> {
// 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<Card[]> {
Expand Down

0 comments on commit 6a89555

Please sign in to comment.