From fd709b99b74d4cd204582c077aaecd2a240d1248 Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Thu, 7 Mar 2024 20:51:14 +0800 Subject: [PATCH] :art: Add kernel API `/api/riff/getRiffCardsByBlockIDs` Fix https://github.com/siyuan-note/siyuan/issues/10535 --- kernel/api/riff.go | 11 ++--------- kernel/model/flashcard.go | 22 ++++++++++++++++++++-- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/kernel/api/riff.go b/kernel/api/riff.go index 7bd00621e..67a621687 100644 --- a/kernel/api/riff.go +++ b/kernel/api/riff.go @@ -40,17 +40,10 @@ func getRiffCardsByBlockIDs(c *gin.Context) { for _, blockID := range blockIDsArg { blockIDs = append(blockIDs, blockID.(string)) } - page := int(arg["page"].(float64)) - pageSize := 20 - if nil != arg["pageSize"] { - pageSize = int(arg["pageSize"].(float64)) - } - blocks, total, pageCount := model.GetFlashcardsByBlockIDs(blockIDs, page, pageSize) + blocks := model.GetFlashcardsByBlockIDs(blockIDs) ret.Data = map[string]interface{}{ - "blocks": blocks, - "total": total, - "pageCount": pageCount, + "blocks": blocks, } } diff --git a/kernel/model/flashcard.go b/kernel/model/flashcard.go index 182b392c6..584ada313 100644 --- a/kernel/model/flashcard.go +++ b/kernel/model/flashcard.go @@ -38,19 +38,37 @@ import ( "github.com/siyuan-note/siyuan/kernel/util" ) -func GetFlashcardsByBlockIDs(blockIDs []string, page, pageSize int) (blocks []*Block, total, pageCount int) { +func GetFlashcardsByBlockIDs(blockIDs []string) (ret []*Block) { deckLock.Lock() defer deckLock.Unlock() waitForSyncingStorages() + ret = []*Block{} deck := Decks[builtinDeckID] if nil == deck { return } cards := deck.GetCardsByBlockIDs(blockIDs) - blocks, total, pageCount = getCardsBlocks(cards, page, pageSize) + blocks, _, _ := getCardsBlocks(cards, 1, math.MaxInt) + + for _, blockID := range blockIDs { + found := false + for _, block := range blocks { + if blockID == block.ID { + found = true + ret = append(ret, block) + break + } + } + if !found { + ret = append(ret, &Block{ + ID: blockID, + Content: Conf.Language(180), + }) + } + } return }