mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-23 18:10:12 +01:00
🎨 Add parameter pageSize for kernel API /api/riff/getRiffCards Fix https://github.com/siyuan-note/siyuan/issues/10445
This commit is contained in:
parent
6f57cbb65b
commit
4173654203
2 changed files with 25 additions and 14 deletions
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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, page
|
|||
allBlockIDs = 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.Card
|
||||
if "" == deckID {
|
||||
|
|
@ -343,11 +343,11 @@ func GetDeckFlashcards(deckID string, page int) (blocks []*Block, total, pageCou
|
|||
cards = 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/9673
|
||||
sort.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, pageCo
|
|||
return due1.Before(due2)
|
||||
})
|
||||
|
||||
const pageSize = 20
|
||||
total = len(cards)
|
||||
pageCount = int(math.Ceil(float64(total) / float64(pageSize)))
|
||||
start := (page - 1) * pageSize
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue