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