Optimize the performance of document tree flashcard loading Fix https://github.com/siyuan-note/siyuan/issues/7967

This commit is contained in:
Liang Ding 2023-04-12 19:41:19 +08:00
parent f30e9893e8
commit 758f65fdff
No known key found for this signature in database
GPG key ID: 136F30F901A2231D
2 changed files with 18 additions and 27 deletions

View file

@ -33,7 +33,6 @@ import (
"github.com/siyuan-note/logging"
"github.com/siyuan-note/riff"
"github.com/siyuan-note/siyuan/kernel/cache"
"github.com/siyuan-note/siyuan/kernel/filesys"
"github.com/siyuan-note/siyuan/kernel/sql"
"github.com/siyuan-note/siyuan/kernel/treenode"
"github.com/siyuan-note/siyuan/kernel/util"
@ -367,32 +366,9 @@ func getTreeSubTreeChildBlocks(rootID string) (treeBlockIDs []string) {
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() {
return ast.WalkContinue
}
treeBlockIDs = append(treeBlockIDs, n.ID)
return ast.WalkContinue
})
bts := treenode.GetBlockTreesByPathPrefix(strings.TrimSuffix(tree.Path, ".sy"))
for _, bt := range bts {
treeBlockIDs = append(treeBlockIDs, bt.ID)
}
return
}

View file

@ -180,6 +180,21 @@ func RemoveBlockTreesByRootID(rootID string) {
}
}
func GetBlockTreesByPathPrefix(pathPrefix string) (ret []*BlockTree) {
blockTrees.Range(func(key, value interface{}) bool {
slice := value.(*btSlice)
slice.m.Lock()
for _, b := range slice.data {
if strings.HasPrefix(b.Path, pathPrefix) {
ret = append(ret, b)
}
}
slice.m.Unlock()
return true
})
return
}
func RemoveBlockTreesByPathPrefix(pathPrefix string) {
var ids []string
blockTrees.Range(func(key, value interface{}) bool {