mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-23 10:00:13 +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)
|
notebookID := arg["id"].(string)
|
||||||
page := int(arg["page"].(float64))
|
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{}{
|
ret.Data = map[string]interface{}{
|
||||||
"blocks": blockIDs,
|
"blocks": blockIDs,
|
||||||
"total": total,
|
"total": total,
|
||||||
|
|
@ -105,7 +109,11 @@ func getTreeRiffCards(c *gin.Context) {
|
||||||
|
|
||||||
rootID := arg["id"].(string)
|
rootID := arg["id"].(string)
|
||||||
page := int(arg["page"].(float64))
|
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{}{
|
ret.Data = map[string]interface{}{
|
||||||
"blocks": blockIDs,
|
"blocks": blockIDs,
|
||||||
"total": total,
|
"total": total,
|
||||||
|
|
@ -124,7 +132,11 @@ func getRiffCards(c *gin.Context) {
|
||||||
|
|
||||||
deckID := arg["id"].(string)
|
deckID := arg["id"].(string)
|
||||||
page := int(arg["page"].(float64))
|
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{}{
|
ret.Data = map[string]interface{}{
|
||||||
"blocks": blocks,
|
"blocks": blocks,
|
||||||
"total": total,
|
"total": total,
|
||||||
|
|
|
||||||
|
|
@ -109,7 +109,7 @@ func ResetFlashcards(typ, id, deckID string, blockIDs []string) {
|
||||||
switch typ {
|
switch typ {
|
||||||
case "notebook":
|
case "notebook":
|
||||||
for i := 1; ; i++ {
|
for i := 1; ; i++ {
|
||||||
pagedBlocks, _, _ := GetNotebookFlashcards(id, i)
|
pagedBlocks, _, _ := GetNotebookFlashcards(id, i, 20)
|
||||||
if 1 > len(pagedBlocks) {
|
if 1 > len(pagedBlocks) {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
@ -120,7 +120,7 @@ func ResetFlashcards(typ, id, deckID string, blockIDs []string) {
|
||||||
}
|
}
|
||||||
case "tree":
|
case "tree":
|
||||||
for i := 1; ; i++ {
|
for i := 1; ; i++ {
|
||||||
pagedBlocks, _, _ := GetTreeFlashcards(id, i)
|
pagedBlocks, _, _ := GetTreeFlashcards(id, i, 20)
|
||||||
if 1 > len(pagedBlocks) {
|
if 1 > len(pagedBlocks) {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
@ -131,7 +131,7 @@ func ResetFlashcards(typ, id, deckID string, blockIDs []string) {
|
||||||
}
|
}
|
||||||
case "deck":
|
case "deck":
|
||||||
for i := 1; ; i++ {
|
for i := 1; ; i++ {
|
||||||
pagedBlocks, _, _ := GetDeckFlashcards(id, i)
|
pagedBlocks, _, _ := GetDeckFlashcards(id, i, 20)
|
||||||
if 1 > len(pagedBlocks) {
|
if 1 > len(pagedBlocks) {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
@ -232,7 +232,7 @@ var (
|
||||||
deckLock = sync.Mutex{}
|
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{}
|
blocks = []*Block{}
|
||||||
|
|
||||||
entries, err := os.ReadDir(filepath.Join(util.DataDir, boxID))
|
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)
|
allBlockIDs = gulu.Str.RemoveDuplicatedElem(allBlockIDs)
|
||||||
cards := deck.GetCardsByBlockIDs(allBlockIDs)
|
cards := deck.GetCardsByBlockIDs(allBlockIDs)
|
||||||
|
|
||||||
blocks, total, pageCount = getCardsBlocks(cards, page)
|
blocks, total, pageCount = getCardsBlocks(cards, page, pageSize)
|
||||||
return
|
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{}
|
blocks = []*Block{}
|
||||||
cards := getTreeSubTreeFlashcards(rootID)
|
cards := getTreeSubTreeFlashcards(rootID)
|
||||||
blocks, total, pageCount = getCardsBlocks(cards, page)
|
blocks, total, pageCount = getCardsBlocks(cards, page, pageSize)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -325,7 +325,7 @@ func getTreeFlashcards(rootID string) (ret []riff.Card) {
|
||||||
return
|
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{}
|
blocks = []*Block{}
|
||||||
var cards []riff.Card
|
var cards []riff.Card
|
||||||
if "" == deckID {
|
if "" == deckID {
|
||||||
|
|
@ -343,11 +343,11 @@ func GetDeckFlashcards(deckID string, page int) (blocks []*Block, total, pageCou
|
||||||
cards = append(cards, deck.GetCardsByBlockIDs(blockIDs)...)
|
cards = append(cards, deck.GetCardsByBlockIDs(blockIDs)...)
|
||||||
}
|
}
|
||||||
|
|
||||||
blocks, total, pageCount = getCardsBlocks(cards, page)
|
blocks, total, pageCount = getCardsBlocks(cards, page, pageSize)
|
||||||
return
|
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 by due date asc https://github.com/siyuan-note/siyuan/pull/9673
|
||||||
sort.Slice(cards, func(i, j int) bool {
|
sort.Slice(cards, func(i, j int) bool {
|
||||||
due1 := cards[i].(*riff.FSRSCard).C.Due
|
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)
|
return due1.Before(due2)
|
||||||
})
|
})
|
||||||
|
|
||||||
const pageSize = 20
|
|
||||||
total = len(cards)
|
total = len(cards)
|
||||||
pageCount = int(math.Ceil(float64(total) / float64(pageSize)))
|
pageCount = int(math.Ceil(float64(total) / float64(pageSize)))
|
||||||
start := (page - 1) * pageSize
|
start := (page - 1) * pageSize
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue