Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

: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

Daniel6c60df3d55a8
diff --git a/kernel/model/sync.go b/kernel/model/sync.go
index c908ec8332..b25eac3f34 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)
-
- bts := treenode.GetBlockTreesByRootID(block.RootID)
- for _, b := range bts {
- cache.RemoveBlockIAL(b.ID)
- }
- cache.RemoveDocIAL(block.Path)
+ rootID := util.GetTreeID(removeFile)
+ removeRootIDs = append(removeRootIDs, rootID)
+
+ 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) {