瀏覽代碼

:bug: The status of flashcards after re-reviewing the previous one is incorrect https://github.com/siyuan-note/siyuan/issues/9988

Daniel 1 年之前
父節點
當前提交
adc42291c6
共有 3 個文件被更改,包括 43 次插入26 次删除
  1. 1 1
      kernel/go.mod
  2. 2 2
      kernel/go.sum
  3. 40 23
      kernel/model/flashcard.go

+ 1 - 1
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

+ 2 - 2
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=

+ 40 - 23
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,43 +1015,59 @@ func getDeckDueCards(deck *riff.Deck, reviewedCardIDs, blockIDs []string, newCar
 
 	newCount := 0
 	reviewCount := 0
-	for _, c := range dues {
-		if nil != skipCardCache[c.ID()] {
-			continue
-		}
-
-		if riff.New == c.GetState() {
-			if newCount >= newCardLimit {
-				continue
-			}
-
+	for _, reviewedCard := range reviewCardCache {
+		if riff.New == reviewedCard.GetState() {
 			newCount++
 		} else {
-			if reviewCount >= reviewCardLimit {
-				continue
-			}
-
 			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() {
-					unreviewedNewCardCount++
+					if newCount < newCardLimit {
+						unreviewedNewCardCountInRound++
+					}
 				} else {
-					unreviewedOldCardCount++
+					if reviewCount < reviewCardLimit {
+						unreviewedOldCardCountInRound++
+					}
 				}
 			}
 		} else {
 			unreviewedCount++
 			if riff.New == c.GetState() {
-				unreviewedNewCardCount++
+				if newCount < newCardLimit {
+					unreviewedNewCardCountInRound++
+				}
 			} else {
-				unreviewedOldCardCount++
+				if reviewCount < reviewCardLimit {
+					unreviewedOldCardCountInRound++
+				}
 			}
 		}
 
+		if riff.New == c.GetState() {
+			if newCount >= newCardLimit {
+				continue
+			}
+
+			newCount++
+		} else {
+			if reviewCount >= reviewCardLimit {
+				continue
+			}
+
+			reviewCount++
+		}
+
 		ret = append(ret, c)
 	}
 	return