From 41736542033e26cbd4fffc933b04ecdda9c5afed Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Mon, 26 Feb 2024 21:00:09 +0800 Subject: [PATCH 1/3] :art: Add parameter `pageSize` for kernel API `/api/riff/getRiffCards` Fix https://github.com/siyuan-note/siyuan/issues/10445 --- kernel/api/riff.go | 18 +++++++++++++++--- kernel/model/flashcard.go | 21 ++++++++++----------- 2 files changed, 25 insertions(+), 14 deletions(-) diff --git a/kernel/api/riff.go b/kernel/api/riff.go index 53b398b2d..6178c8e18 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.go index 8f9637c55..8459d0522 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, 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 From c359e8cea1940215e472b341061a2e71b01e241c Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Mon, 26 Feb 2024 21:01:37 +0800 Subject: [PATCH 2/3] :memo: Update changelogs --- app/changelogs/v3.0.1/v3.0.1.md | 1 + app/changelogs/v3.0.1/v3.0.1_zh_CHT.md | 1 + app/changelogs/v3.0.1/v3.0.1_zh_CN.md | 1 + 3 files changed, 3 insertions(+) diff --git a/app/changelogs/v3.0.1/v3.0.1.md b/app/changelogs/v3.0.1/v3.0.1.md index 6377a2ff2..65a3a75a8 100644 --- a/app/changelogs/v3.0.1/v3.0.1.md +++ b/app/changelogs/v3.0.1/v3.0.1.md @@ -41,6 +41,7 @@ Below are the detailed changes in this version. * [Improve internal kernel API `/api/attr/batchSetBlockAttrs`](https://github.com/siyuan-note/siyuan/issues/10401) * [Add internal kernel API `/api/riff/batchSetRiffCardsDueTime`](https://github.com/siyuan-note/siyuan/issues/10423) +* [Add parameter `pageSize` for kernel API `/api/riff/getRiffCards`](https://github.com/siyuan-note/siyuan/issues/10445) ## Download diff --git a/app/changelogs/v3.0.1/v3.0.1_zh_CHT.md b/app/changelogs/v3.0.1/v3.0.1_zh_CHT.md index 7533351e6..7a489610a 100644 --- a/app/changelogs/v3.0.1/v3.0.1_zh_CHT.md +++ b/app/changelogs/v3.0.1/v3.0.1_zh_CHT.md @@ -41,6 +41,7 @@ * [改進內部核心 API `/api/attr/batchSetBlockAttrs`](https://github.com/siyuan-note/siyuan/issues/10401) * [新增內部核心 API `/api/riff/batchSetRiffCardsDueTime`](https://github.com/siyuan-note/siyuan/issues/10423) +* [核心 API `/api/riff/getRiffCards` 新增參數 `pageSize`](https://github.com/siyuan-note/siyuan/issues/10445) ## 下載 diff --git a/app/changelogs/v3.0.1/v3.0.1_zh_CN.md b/app/changelogs/v3.0.1/v3.0.1_zh_CN.md index a695879d4..ee24699c3 100644 --- a/app/changelogs/v3.0.1/v3.0.1_zh_CN.md +++ b/app/changelogs/v3.0.1/v3.0.1_zh_CN.md @@ -41,6 +41,7 @@ * [改进内部内核 API `/api/attr/batchSetBlockAttrs`](https://github.com/siyuan-note/siyuan/issues/10401) * [添加内部内核 API `/api/riff/batchSetRiffCardsDueTime`](https://github.com/siyuan-note/siyuan/issues/10423) +* [内核 API `/api/riff/getRiffCards` 添加参数 `pageSize`](https://github.com/siyuan-note/siyuan/issues/10445) ## 下载 From 7c5d10953446c05f2b947ba9e243644eb13d18bb Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Mon, 26 Feb 2024 21:07:54 +0800 Subject: [PATCH 3/3] :memo: Update changelogs --- app/changelogs/v3.0.1/v3.0.1.md | 1 + app/changelogs/v3.0.1/v3.0.1_zh_CHT.md | 1 + app/changelogs/v3.0.1/v3.0.1_zh_CN.md | 1 + 3 files changed, 3 insertions(+) diff --git a/app/changelogs/v3.0.1/v3.0.1.md b/app/changelogs/v3.0.1/v3.0.1.md index 65a3a75a8..ed51abc6a 100644 --- a/app/changelogs/v3.0.1/v3.0.1.md +++ b/app/changelogs/v3.0.1/v3.0.1.md @@ -14,6 +14,7 @@ Below are the detailed changes in this version. * [`Create doc above/below` function can also be used when notebook is custom sort](https://github.com/siyuan-note/siyuan/issues/10381) * [Improve cursor position after deletion](https://github.com/siyuan-note/siyuan/issues/10389) * [Improve deletion of the empty block below thematic breaks](https://github.com/siyuan-note/siyuan/issues/10393) +* [Improve the performance of pop-up windows when creating columns in the database](https://github.com/siyuan-note/siyuan/issues/10394) * [Floating window remains displayed while it has menu](https://github.com/siyuan-note/siyuan/issues/10397) * [Update outline after closing all editors](https://github.com/siyuan-note/siyuan/issues/10400) * [Candidate values of the database relation fields are no longer subject to view filtering](https://github.com/siyuan-note/siyuan/issues/10411) diff --git a/app/changelogs/v3.0.1/v3.0.1_zh_CHT.md b/app/changelogs/v3.0.1/v3.0.1_zh_CHT.md index 7a489610a..3d9354b1c 100644 --- a/app/changelogs/v3.0.1/v3.0.1_zh_CHT.md +++ b/app/changelogs/v3.0.1/v3.0.1_zh_CHT.md @@ -14,6 +14,7 @@ * [`上方/下方新文件` 功能在筆記本等級自訂排序時可用](https://github.com/siyuan-note/siyuan/issues/10381) * [改進刪除作業後的遊標位置](https://github.com/siyuan-note/siyuan/issues/10389) * [改進分隔線下方空格刪除操作](https://github.com/siyuan-note/siyuan/issues/10393) +* [改進資料庫建立列時彈出視窗的效能](https://github.com/siyuan-note/siyuan/issues/10394) * [浮窗中有選單時保持顯示](https://github.com/siyuan-note/siyuan/issues/10397) * [關閉所有編輯器後更新大綱](https://github.com/siyuan-note/siyuan/issues/10400) * [資料庫關聯欄位候選值不再受視圖過濾影響](https://github.com/siyuan-note/siyuan/issues/10411) diff --git a/app/changelogs/v3.0.1/v3.0.1_zh_CN.md b/app/changelogs/v3.0.1/v3.0.1_zh_CN.md index ee24699c3..0eab14766 100644 --- a/app/changelogs/v3.0.1/v3.0.1_zh_CN.md +++ b/app/changelogs/v3.0.1/v3.0.1_zh_CN.md @@ -14,6 +14,7 @@ * [`在上方/下方新建文档` 功能在笔记本级自定义排序时可用](https://github.com/siyuan-note/siyuan/issues/10381) * [改进删除操作后的光标位置](https://github.com/siyuan-note/siyuan/issues/10389) * [改进分隔线下方空格删除操作](https://github.com/siyuan-note/siyuan/issues/10393) +* [改进数据库创建列时弹出窗口的性能](https://github.com/siyuan-note/siyuan/issues/10394) * [浮窗中有菜单时保持显示](https://github.com/siyuan-note/siyuan/issues/10397) * [关闭所有编辑器后更新大纲](https://github.com/siyuan-note/siyuan/issues/10400) * [数据库关联字段候选值不再受视图过滤影响](https://github.com/siyuan-note/siyuan/issues/10411)