From b999d293d5ffd80e2daae0414ead236175e9ae69 Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Thu, 29 Dec 2022 21:54:10 +0800 Subject: [PATCH] =?UTF-8?q?:art:=20=E6=94=AF=E6=8C=81=E6=B5=8F=E8=A7=88?= =?UTF-8?q?=E5=8D=A1=E5=8C=85=E5=86=85=E7=9A=84=E9=97=AA=E5=8D=A1=20https:?= =?UTF-8?q?//github.com/siyuan-note/siyuan/issues/6943?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kernel/model/flashcard.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/kernel/model/flashcard.go b/kernel/model/flashcard.go index c292b9b0d..8051c8c17 100644 --- a/kernel/model/flashcard.go +++ b/kernel/model/flashcard.go @@ -18,6 +18,7 @@ package model import ( "errors" + "math" "os" "path/filepath" "sort" @@ -45,14 +46,15 @@ func GetFlashcards(deckID string, page int) (blockIDs []string, total, pageCount return } + const pageSize = 20 var allBlockIDs []string for bID, _ := range deck.BlockCard { allBlockIDs = append(allBlockIDs, bID) } sort.Strings(allBlockIDs) - start := (page - 1) * 20 - end := page * 20 + start := (page - 1) * pageSize + end := page * pageSize if start > len(allBlockIDs) { return } @@ -61,7 +63,7 @@ func GetFlashcards(deckID string, page int) (blockIDs []string, total, pageCount } blockIDs = allBlockIDs[start:end] total = len(allBlockIDs) - pageCount = total / 20 + pageCount = int(math.Ceil(float64(total) / float64(pageSize))) return }