An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:art: Add parameter `pageSize` for kernel API `/api/riff/getRiffCards` Fix https://github.com/siyuan-note/siyuan/issues/10445
Daniel41736542033e
diff --git a/kernel/api/riff.go b/kernel/api/riff.goindex 53b398b2dd..6178c8e181 100644--- a/kernel/api/riff.go+++ b/kernel/api/riff.go@@ -86,7 +86,11 @@ func getNotebookRiffCards(c *gin.Context) {notebookID := arg["id"].(string)page := int(arg["page"].(float64))- blockIDs, total, pageCount := model.GetNotebookFlashcards(notebookID, page)+ pageSize := 20+ if nil != arg["pageSize"] {+ pageSize = int(arg["pageSize"].(float64))+ }+ blockIDs, total, pageCount := model.GetNotebookFlashcards(notebookID, page, pageSize)ret.Data = map[string]interface{}{"blocks": blockIDs,"total": total,@@ -105,7 +109,11 @@ func getTreeRiffCards(c *gin.Context) {rootID := arg["id"].(string)page := int(arg["page"].(float64))- blockIDs, total, pageCount := model.GetTreeFlashcards(rootID, page)+ pageSize := 20+ if nil != arg["pageSize"] {+ pageSize = int(arg["pageSize"].(float64))+ }+ blockIDs, total, pageCount := model.GetTreeFlashcards(rootID, page, pageSize)ret.Data = map[string]interface{}{"blocks": blockIDs,"total": total,@@ -124,7 +132,11 @@ func getRiffCards(c *gin.Context) {deckID := arg["id"].(string)page := int(arg["page"].(float64))- blocks, total, pageCount := model.GetDeckFlashcards(deckID, page)+ pageSize := 20+ if nil != arg["pageSize"] {+ pageSize = int(arg["pageSize"].(float64))+ }+ blocks, total, pageCount := model.GetDeckFlashcards(deckID, page, pageSize)ret.Data = map[string]interface{}{"blocks": blocks,"total": total,diff --git a/kernel/model/flashcard.go b/kernel/model/flashcard.goindex 8f9637c55c..8459d05225 100644--- a/kernel/model/flashcard.go+++ b/kernel/model/flashcard.go@@ -109,7 +109,7 @@ func ResetFlashcards(typ, id, deckID string, blockIDs []string) {switch typ {case "notebook":for i := 1; ; i++ {- pagedBlocks, _, _ := GetNotebookFlashcards(id, i)+ pagedBlocks, _, _ := GetNotebookFlashcards(id, i, 20)if 1 > len(pagedBlocks) {break}@@ -120,7 +120,7 @@ func ResetFlashcards(typ, id, deckID string, blockIDs []string) {}case "tree":for i := 1; ; i++ {- pagedBlocks, _, _ := GetTreeFlashcards(id, i)+ pagedBlocks, _, _ := GetTreeFlashcards(id, i, 20)if 1 > len(pagedBlocks) {break}@@ -131,7 +131,7 @@ func ResetFlashcards(typ, id, deckID string, blockIDs []string) {}case "deck":for i := 1; ; i++ {- pagedBlocks, _, _ := GetDeckFlashcards(id, i)+ pagedBlocks, _, _ := GetDeckFlashcards(id, i, 20)if 1 > len(pagedBlocks) {break}@@ -232,7 +232,7 @@ var (deckLock = sync.Mutex{})-func GetNotebookFlashcards(boxID string, page int) (blocks []*Block, total, pageCount int) {+func GetNotebookFlashcards(boxID string, page, pageSize int) (blocks []*Block, total, pageCount int) {blocks = []*Block{}entries, err := os.ReadDir(filepath.Join(util.DataDir, boxID))@@ -276,14 +276,14 @@ func GetNotebookFlashcards(boxID string, page int) (blocks []*Block, total, pageallBlockIDs = gulu.Str.RemoveDuplicatedElem(allBlockIDs)cards := deck.GetCardsByBlockIDs(allBlockIDs)- blocks, total, pageCount = getCardsBlocks(cards, page)+ blocks, total, pageCount = getCardsBlocks(cards, page, pageSize)return}-func GetTreeFlashcards(rootID string, page int) (blocks []*Block, total, pageCount int) {+func GetTreeFlashcards(rootID string, page, pageSize int) (blocks []*Block, total, pageCount int) {blocks = []*Block{}cards := getTreeSubTreeFlashcards(rootID)- blocks, total, pageCount = getCardsBlocks(cards, page)+ blocks, total, pageCount = getCardsBlocks(cards, page, pageSize)return}@@ -325,7 +325,7 @@ func getTreeFlashcards(rootID string) (ret []riff.Card) {return}-func GetDeckFlashcards(deckID string, page int) (blocks []*Block, total, pageCount int) {+func GetDeckFlashcards(deckID string, page, pageSize int) (blocks []*Block, total, pageCount int) {blocks = []*Block{}var cards []riff.Cardif "" == deckID {@@ -343,11 +343,11 @@ func GetDeckFlashcards(deckID string, page int) (blocks []*Block, total, pageCoucards = append(cards, deck.GetCardsByBlockIDs(blockIDs)...)}- blocks, total, pageCount = getCardsBlocks(cards, page)+ blocks, total, pageCount = getCardsBlocks(cards, page, pageSize)return}-func getCardsBlocks(cards []riff.Card, page int) (blocks []*Block, total, pageCount int) {+func getCardsBlocks(cards []riff.Card, page, pageSize int) (blocks []*Block, total, pageCount int) {// sort by due date asc https://github.com/siyuan-note/siyuan/pull/9673sort.Slice(cards, func(i, j int) bool {due1 := cards[i].(*riff.FSRSCard).C.Due@@ -355,7 +355,6 @@ func getCardsBlocks(cards []riff.Card, page int) (blocks []*Block, total, pageCoreturn due1.Before(due2)})- const pageSize = 20total = len(cards)pageCount = int(math.Ceil(float64(total) / float64(pageSize)))start := (page - 1) * pageSize