From 3d36355e2bd10995991ba97e27e6629c73db727a Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Tue, 9 Jul 2024 23:25:28 +0800 Subject: [PATCH] :zap: Improve spaced repetition loading performance https://github.com/siyuan-note/siyuan/issues/11927 --- kernel/model/flashcard.go | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/kernel/model/flashcard.go b/kernel/model/flashcard.go index 9cb7d3cbb..08e7ceb53 100644 --- a/kernel/model/flashcard.go +++ b/kernel/model/flashcard.go @@ -1078,18 +1078,24 @@ func getDeckDueCards(deck *riff.Deck, reviewedCardIDs, blockIDs []string, newCar var retNew, retOld []riff.Card dues := deck.Dues() - - var tmp []riff.Card + toChecks := map[string]riff.Card{} for _, c := range dues { if 0 < len(blockIDs) && !gulu.Str.Contains(c.BlockID(), blockIDs) { continue } - if !treenode.ExistBlockTree(c.BlockID()) { - continue + toChecks[c.BlockID()] = c + } + var toCheckBlockIDs []string + var tmp []riff.Card + for bID, _ := range toChecks { + toCheckBlockIDs = append(toCheckBlockIDs, bID) + } + checkResult := treenode.ExistBlockTrees(toCheckBlockIDs) + for bID, exists := range checkResult { + if exists { + tmp = append(tmp, toChecks[bID]) } - - tmp = append(tmp, c) } dues = tmp