An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:art: 支持基于文档复习闪卡 https://github.com/siyuan-note/siyuan/issues/7057
Liang Ding9fd9ccd0385b
diff --git a/kernel/model/flashcard.go b/kernel/model/flashcard.goindex 481e4f2f85..61d6ba6953 100644--- a/kernel/model/flashcard.go+++ b/kernel/model/flashcard.go@@ -45,40 +45,7 @@ var deckLock = sync.Mutex{}func GetTreeFlashcards(rootID string, page int) (blocks []*Block, total, pageCount int) {blocks = []*Block{}- tree, err := loadTreeByBlockID(rootID)- if nil != err {- return- }-- trees := []*parse.Tree{tree}- box := Conf.Box(tree.Box)- luteEngine := util.NewLute()- files := box.ListFiles(tree.Path)- for _, subFile := range files {- if !strings.HasSuffix(subFile.path, ".sy") {- continue- }-- subTree, loadErr := filesys.LoadTree(box.ID, subFile.path, luteEngine)- if nil != loadErr {- continue- }-- trees = append(trees, subTree)- }-- treeBlockIDs := map[string]bool{}- for _, t := range trees {- ast.Walk(t.Root, func(n *ast.Node, entering bool) ast.WalkStatus {- if !entering || !n.IsBlock() || ast.NodeDocument == n.Type {- return ast.WalkContinue- }-- treeBlockIDs[n.ID] = true- return ast.WalkContinue- })- }-+ treeBlockIDs := getTreeSubTreeChildBlocks(rootID)var allBlockIDs []stringconst pageSize = 20deck := Decks[builtinDeckID]@@ -229,26 +196,12 @@ func GetTreeDueFlashcards(rootID string) (ret []*Flashcard, err error) {return}- tree, err := loadTreeByBlockID(rootID)- if nil != err {- return- }-- blockIDs := map[string]bool{}- 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- })-+ treeBlockIDs := getTreeSubTreeChildBlocks(rootID)cards := deck.Dues()now := time.Now()for _, card := range cards {blockID := card.BlockID()- if !blockIDs[blockID] {+ if !treeBlockIDs[blockID] {continue}@@ -269,6 +222,44 @@ func GetTreeDueFlashcards(rootID string) (ret []*Flashcard, err error) {return}+func getTreeSubTreeChildBlocks(rootID string) (treeBlockIDs map[string]bool) {+ treeBlockIDs = map[string]bool{}++ tree, err := loadTreeByBlockID(rootID)+ if nil != err {+ return+ }++ trees := []*parse.Tree{tree}+ box := Conf.Box(tree.Box)+ luteEngine := util.NewLute()+ files := box.ListFiles(tree.Path)+ for _, subFile := range files {+ if !strings.HasSuffix(subFile.path, ".sy") {+ continue+ }++ subTree, loadErr := filesys.LoadTree(box.ID, subFile.path, luteEngine)+ if nil != loadErr {+ continue+ }++ trees = append(trees, subTree)+ }++ for _, t := range trees {+ ast.Walk(t.Root, func(n *ast.Node, entering bool) ast.WalkStatus {+ if !entering || !n.IsBlock() || ast.NodeDocument == n.Type {+ return ast.WalkContinue+ }++ treeBlockIDs[n.ID] = true+ return ast.WalkContinue+ })+ }+ return+}+func GetDueFlashcards(deckID string) (ret []*Flashcard, err error) {deckLock.Lock()defer deckLock.Unlock()