From 6c60df3d55a8b0d48f67916cf77ffebfd52b8617 Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Tue, 10 Feb 2026 09:26:18 +0800 Subject: [PATCH] :art: Caching tree data to improve performance and reduce disk read operations https://github.com/siyuan-note/siyuan/issues/16961 https://github.com/siyuan-note/siyuan/issues/16991 Signed-off-by: Daniel <845765@qq.com> --- kernel/model/sync.go | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/kernel/model/sync.go b/kernel/model/sync.go index c908ec833..b25eac3f3 100644 --- a/kernel/model/sync.go +++ b/kernel/model/sync.go @@ -292,23 +292,23 @@ func removeIndexes(removeFilePaths []string) (removeRootIDs []string) { continue } - id := util.GetTreeID(removeFile) - removeRootIDs = append(removeRootIDs, id) - block := treenode.GetBlockTree(id) - if nil != block { - msg := fmt.Sprintf(Conf.Language(39), block.RootID) - util.IncBootProgress(bootProgressPart, msg) - util.PushStatusBar(msg) + rootID := util.GetTreeID(removeFile) + removeRootIDs = append(removeRootIDs, rootID) - bts := treenode.GetBlockTreesByRootID(block.RootID) - for _, b := range bts { - cache.RemoveBlockIAL(b.ID) - } - cache.RemoveDocIAL(block.Path) + msg := fmt.Sprintf(Conf.Language(39), rootID) + util.IncBootProgress(bootProgressPart, msg) + util.PushStatusBar(msg) - treenode.RemoveBlockTreesByRootID(block.RootID) - sql.RemoveTreeQueue(block.RootID) + cache.RemoveTreeData(rootID) + sql.RemoveTreeQueue(rootID) + bts := treenode.GetBlockTreesByRootID(rootID) + for _, b := range bts { + cache.RemoveBlockIAL(b.ID) } + if block := treenode.GetBlockTree(rootID); nil != block { + cache.RemoveDocIAL(block.Path) + } + treenode.RemoveBlockTreesByRootID(rootID) } if 1 > len(removeRootIDs) { @@ -341,6 +341,8 @@ func upsertIndexes(upsertFilePaths []string) (upsertRootIDs []string) { util.IncBootProgress(bootProgressPart, msg) util.PushStatusBar(msg) + rootID := util.GetTreeID(p) + cache.RemoveTreeData(rootID) tree, err0 := filesys.LoadTree(box, p, luteEngine) if nil != err0 { continue @@ -348,13 +350,13 @@ func upsertIndexes(upsertFilePaths []string) (upsertRootIDs []string) { treenode.UpsertBlockTree(tree) sql.UpsertTreeQueue(tree) - bts := treenode.GetBlockTreesByRootID(tree.ID) + bts := treenode.GetBlockTreesByRootID(rootID) for _, b := range bts { cache.RemoveBlockIAL(b.ID) } cache.RemoveDocIAL(tree.Path) - upsertRootIDs = append(upsertRootIDs, tree.Root.ID) + upsertRootIDs = append(upsertRootIDs, rootID) } if 1 > len(upsertRootIDs) {