浏览代码

:art: 支持基于文档复习闪卡 https://github.com/siyuan-note/siyuan/issues/7057

Liang Ding 2 年之前
父节点
当前提交
f552b17f53
共有 2 个文件被更改,包括 7 次插入22 次删除
  1. 0 7
      kernel/api/riff.go
  2. 7 15
      kernel/model/flashcard.go

+ 0 - 7
kernel/api/riff.go

@@ -76,13 +76,6 @@ func getTreeRiffDueCards(c *gin.Context) {
 	}
 
 	rootID := arg["rootID"].(string)
-	err := model.AddTreeFlashcards(rootID)
-	if nil != err {
-		ret.Code = -1
-		ret.Msg = err.Error()
-		return
-	}
-
 	cards, err := model.GetTreeDueFlashcards(rootID)
 	if nil != err {
 		ret.Code = -1

+ 7 - 15
kernel/model/flashcard.go

@@ -143,9 +143,14 @@ func GetTreeDueFlashcards(rootID string) (ret []*Flashcard, err error) {
 	}
 
 	blockIDs := map[string]bool{}
-	for n := tree.Root.FirstChild; nil != n; n = n.Next {
+	ast.Walk(tree.Root, func(n *ast.Node, entering bool) ast.WalkStatus {
+		if !entering || !n.IsBlock() {
+			return ast.WalkContinue
+		}
+
 		blockIDs[n.ID] = true
-	}
+		return ast.WalkContinue
+	})
 
 	cards := deck.Dues()
 	now := time.Now()
@@ -336,19 +341,6 @@ func RemoveFlashcards(deckID string, blockIDs []string) (err error) {
 	return
 }
 
-func AddTreeFlashcards(rootID string) (err error) {
-	tree, err := loadTreeByBlockID(rootID)
-	if nil != err {
-		return
-	}
-
-	var blockIDs []string
-	for n := tree.Root.FirstChild; nil != n; n = n.Next {
-		blockIDs = append(blockIDs, n.ID)
-	}
-	return AddFlashcards(builtinDeckID, blockIDs)
-}
-
 func AddFlashcards(deckID string, blockIDs []string) (err error) {
 	deckLock.Lock()
 	defer deckLock.Unlock()