From adc42291c6be8741458efc0daf0366326a3c5b4c Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Tue, 26 Dec 2023 23:23:26 +0800 Subject: [PATCH 1/2] :bug: The status of flashcards after re-reviewing the previous one is incorrect https://github.com/siyuan-note/siyuan/issues/9988 --- kernel/go.mod | 2 +- kernel/go.sum | 4 +-- kernel/model/flashcard.go | 63 +++++++++++++++++++++++++-------------- 3 files changed, 43 insertions(+), 26 deletions(-) diff --git a/kernel/go.mod b/kernel/go.mod index b0c56dc97..5eb924eec 100644 --- a/kernel/go.mod +++ b/kernel/go.mod @@ -56,7 +56,7 @@ require ( github.com/siyuan-note/filelock v0.0.0-20231211015131-3b3dfabdce9c github.com/siyuan-note/httpclient v0.0.0-20231219001541-d75e4dce39fa github.com/siyuan-note/logging v0.0.0-20231208035918-61f884c854f0 - github.com/siyuan-note/riff v0.0.0-20231222032533-1f1b309dbc08 + github.com/siyuan-note/riff v0.0.0-20231226152006-8833f8b9a6c1 github.com/spf13/cast v1.6.0 github.com/steambap/captcha v1.4.1 github.com/studio-b12/gowebdav v0.9.0 diff --git a/kernel/go.sum b/kernel/go.sum index b9c5c0596..483a8ce75 100644 --- a/kernel/go.sum +++ b/kernel/go.sum @@ -366,8 +366,8 @@ github.com/siyuan-note/httpclient v0.0.0-20231219001541-d75e4dce39fa h1:kfWxJzNP github.com/siyuan-note/httpclient v0.0.0-20231219001541-d75e4dce39fa/go.mod h1:ejS8ChupXGP89C8N4nM+xhyxVVf/IfcwOXboql6o3+g= github.com/siyuan-note/logging v0.0.0-20231208035918-61f884c854f0 h1:+XjUr9UMXsczdO2bGA72p/k9wa2ShPb8ybi7CDBJ7HQ= github.com/siyuan-note/logging v0.0.0-20231208035918-61f884c854f0/go.mod h1:6mRFtAAvYPn3cDzqvyv+t8BVPGqpONDMMb5ywOhY1D4= -github.com/siyuan-note/riff v0.0.0-20231222032533-1f1b309dbc08 h1:vPZqpEIT8gqtFM23FHbxhaCeCzccHB/KFR7OEZfAt0U= -github.com/siyuan-note/riff v0.0.0-20231222032533-1f1b309dbc08/go.mod h1:wLzj67jwt8PM+qWPGlC4V7m0fzkUlkwPKf9vLF6ru/k= +github.com/siyuan-note/riff v0.0.0-20231226152006-8833f8b9a6c1 h1:MziLTkbS4qTpeuANYEQQK5yQRSkdRXXNs+JKksbaMQk= +github.com/siyuan-note/riff v0.0.0-20231226152006-8833f8b9a6c1/go.mod h1:wLzj67jwt8PM+qWPGlC4V7m0fzkUlkwPKf9vLF6ru/k= github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM= github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= github.com/smartystreets/goconvey v1.6.7 h1:I6tZjLXD2Q1kjvNbIzB1wvQBsXmKXiVrhpRE8ZjP5jY= diff --git a/kernel/model/flashcard.go b/kernel/model/flashcard.go index 437abfcc9..b7e7ba9fa 100644 --- a/kernel/model/flashcard.go +++ b/kernel/model/flashcard.go @@ -390,7 +390,7 @@ func ReviewFlashcard(deckID, cardID string, rating riff.Rating, reviewedCardIDs delete(skipCardCache, cardID) } else { // 首次复习该卡片,将卡片缓存以便后续支持撤销后再次复习 - reviewCardCache[cardID] = card + reviewCardCache[cardID] = card.Clone() } log := deck.Review(cardID, rating) @@ -404,8 +404,8 @@ func ReviewFlashcard(deckID, cardID string, rating riff.Rating, reviewedCardIDs return } - dueCards, _, _, _ := getDueFlashcards(deckID, reviewedCardIDs) - if 1 > len(dueCards) { + _, unreviewedCount, _, _ := getDueFlashcards(deckID, reviewedCardIDs) + if 1 > unreviewedCount { // 该卡包中没有待复习的卡片了,说明最后一张卡片已经复习完了,清空撤销缓存和跳过缓存 reviewCardCache = map[string]riff.Card{} skipCardCache = map[string]riff.Card{} @@ -988,7 +988,7 @@ func getDeckIDs() (deckIDs []string) { return } -func getDeckDueCards(deck *riff.Deck, reviewedCardIDs, blockIDs []string, newCardLimit, reviewCardLimit int) (ret []riff.Card, unreviewedCount, unreviewedNewCardCount, unreviewedOldCardCount int) { +func getDeckDueCards(deck *riff.Deck, reviewedCardIDs, blockIDs []string, newCardLimit, reviewCardLimit int) (ret []riff.Card, unreviewedCount, unreviewedNewCardCountInRound, unreviewedOldCardCountInRound int) { ret = []riff.Card{} dues := deck.Dues() @@ -1006,7 +1006,8 @@ func getDeckDueCards(deck *riff.Deck, reviewedCardIDs, blockIDs []string, newCar } dues = tmp - if 1 > len(reviewedCardIDs) { + reviewedCardCount := len(reviewedCardIDs) + if 1 > reviewedCardCount { // 未传入已复习的卡片 ID,说明是开始新的复习,需要清空缓存 reviewCardCache = map[string]riff.Card{} skipCardCache = map[string]riff.Card{} @@ -1014,11 +1015,45 @@ func getDeckDueCards(deck *riff.Deck, reviewedCardIDs, blockIDs []string, newCar newCount := 0 reviewCount := 0 + for _, reviewedCard := range reviewCardCache { + if riff.New == reviewedCard.GetState() { + newCount++ + } else { + reviewCount++ + } + } + for _, c := range dues { if nil != skipCardCache[c.ID()] { continue } + if 0 < len(reviewedCardIDs) { + if !gulu.Str.Contains(c.ID(), reviewedCardIDs) { + unreviewedCount++ + if riff.New == c.GetState() { + if newCount < newCardLimit { + unreviewedNewCardCountInRound++ + } + } else { + if reviewCount < reviewCardLimit { + unreviewedOldCardCountInRound++ + } + } + } + } else { + unreviewedCount++ + if riff.New == c.GetState() { + if newCount < newCardLimit { + unreviewedNewCardCountInRound++ + } + } else { + if reviewCount < reviewCardLimit { + unreviewedOldCardCountInRound++ + } + } + } + if riff.New == c.GetState() { if newCount >= newCardLimit { continue @@ -1033,24 +1068,6 @@ func getDeckDueCards(deck *riff.Deck, reviewedCardIDs, blockIDs []string, newCar reviewCount++ } - if 0 < len(reviewedCardIDs) { - if !gulu.Str.Contains(c.ID(), reviewedCardIDs) { - unreviewedCount++ - if riff.New == c.GetState() { - unreviewedNewCardCount++ - } else { - unreviewedOldCardCount++ - } - } - } else { - unreviewedCount++ - if riff.New == c.GetState() { - unreviewedNewCardCount++ - } else { - unreviewedOldCardCount++ - } - } - ret = append(ret, c) } return From abd79c29a8211b17409eb7fe702c39283b712c1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yingyi=20/=20=E9=A2=96=E9=80=B8?= <49649786+Zuoqiu-Yingyi@users.noreply.github.com> Date: Tue, 26 Dec 2023 23:27:10 +0800 Subject: [PATCH 2/2] Improve kernel API `/api/notebook/*` (#9987) * :bug: fix some notebook API * Update notebook.go --- kernel/api/notebook.go | 35 ++++++++++++++++++++++++++++++----- kernel/model/conf.go | 9 +++++++++ 2 files changed, 39 insertions(+), 5 deletions(-) diff --git a/kernel/api/notebook.go b/kernel/api/notebook.go index 8a18d66eb..f750ab122 100644 --- a/kernel/api/notebook.go +++ b/kernel/api/notebook.go @@ -150,13 +150,20 @@ func createNotebook(c *gin.Context) { return } + box := model.Conf.Box(id) + if nil == box { + ret.Code = -1 + ret.Msg = "opened notebook [" + id + "] not found" + return + } + ret.Data = map[string]interface{}{ - "notebook": model.Conf.Box(id), + "notebook": box, } evt := util.NewCmdResult("createnotebook", 0, util.PushModeBroadcast) evt.Data = map[string]interface{}{ - "box": model.Conf.Box(id), + "box": box, "existed": existed, } util.PushEvent(evt) @@ -194,9 +201,16 @@ func openNotebook(c *gin.Context) { return } + box := model.Conf.Box(notebook) + if nil == box { + ret.Code = -1 + ret.Msg = "opened notebook [" + notebook + "] not found" + return + } + evt := util.NewCmdResult("mount", 0, util.PushModeBroadcast) evt.Data = map[string]interface{}{ - "box": model.Conf.Box(notebook), + "box": box, "existed": existed, } evt.Callback = arg["callback"] @@ -233,7 +247,13 @@ func getNotebookConf(c *gin.Context) { return } - box := model.Conf.Box(notebook) + box := model.Conf.GetBox(notebook) + if nil == box { + ret.Code = -1 + ret.Msg = "notebook [" + notebook + "] not found" + return + } + ret.Data = map[string]interface{}{ "box": box.ID, "name": box.Name, @@ -255,7 +275,12 @@ func setNotebookConf(c *gin.Context) { return } - box := model.Conf.Box(notebook) + box := model.Conf.GetBox(notebook) + if nil == box { + ret.Code = -1 + ret.Msg = "notebook [" + notebook + "] not found" + return + } param, err := gulu.JSON.MarshalJSON(arg["conf"]) if nil != err { diff --git a/kernel/model/conf.go b/kernel/model/conf.go index c26a7c0fc..72bbe3bef 100644 --- a/kernel/model/conf.go +++ b/kernel/model/conf.go @@ -649,6 +649,15 @@ func (conf *AppConf) Box(boxID string) *Box { return nil } +func (conf *AppConf) GetBox(boxID string) *Box { + for _, box := range conf.GetBoxes() { + if box.ID == boxID { + return box + } + } + return nil +} + func (conf *AppConf) BoxNames(boxIDs []string) (ret map[string]string) { ret = map[string]string{}