From c5b1279c82c077dd53a26dd94eb068bbabb42df1 Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Thu, 22 Dec 2022 10:59:33 +0800 Subject: [PATCH] =?UTF-8?q?:art:=20=E6=94=AF=E6=8C=81=E9=97=B4=E9=9A=94?= =?UTF-8?q?=E5=A4=8D=E4=B9=A0=20https://github.com/siyuan-note/siyuan/issu?= =?UTF-8?q?es/6710?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kernel/api/riff.go | 1 - kernel/model/flashcard.go | 36 +++++++++++++++++++++++++++--------- 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/kernel/api/riff.go b/kernel/api/riff.go index f471d6133..af81ab68f 100644 --- a/kernel/api/riff.go +++ b/kernel/api/riff.go @@ -56,7 +56,6 @@ func getRiffDueCards(c *gin.Context) { } deckID := arg["deckID"].(string) - cards, err := model.GetDueFlashcards(deckID) if nil != err { ret.Code = -1 diff --git a/kernel/model/flashcard.go b/kernel/model/flashcard.go index d0e1b3b2d..aac181e8d 100644 --- a/kernel/model/flashcard.go +++ b/kernel/model/flashcard.go @@ -45,12 +45,11 @@ func ReviewFlashcard(deckID string, blockID string, rating riff.Rating) (err err return } -type Flashcard struct { - ID string - BlockID string -} +func GetDueFlashcards(deckID string) (ret []string, err error) { + if "" == deckID { + return getAllDueFlashcards() + } -func GetDueFlashcards(deckID string) (ret []*Flashcard, err error) { deckLock.Lock() deck := Decks[deckID] deckLock.Unlock() @@ -62,10 +61,29 @@ func GetDueFlashcards(deckID string) (ret []*Flashcard, err error) { if nil != getErr { continue } - ret = append(ret, &Flashcard{ - ID: card.ID(), - BlockID: blockID, - }) + ret = append(ret, blockID) + } + return +} + +func getAllDueFlashcards() (ret []string, err error) { + blockIDs := map[string]bool{} + for _, deck := range Decks { + cards := deck.Dues() + for _, card := range cards { + blockID := card.BlockID() + _, getErr := GetBlock(blockID) + if nil != getErr { + continue + } + + if blockIDs[blockID] { + continue + } + + ret = append(ret, blockID) + blockIDs[blockID] = true + } } return }