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: 尝试定位 未找到 ID 为 xxx 的内容块 https://github.com/siyuan-note/siyuan/issues/7215
Liang Ding7aea03db69dd
diff --git a/kernel/job/cron.go b/kernel/job/cron.goindex 1e3caae626..ffb98438db 100644--- a/kernel/job/cron.go+++ b/kernel/job/cron.go@@ -30,7 +30,7 @@ import (func StartCron() {go every(100*time.Millisecond, task.ExecTaskJob)go every(5*time.Second, task.StatusJob)- go every(3*time.Second, treenode.SaveBlockTreeJob)+ go every(5*time.Second, treenode.SaveBlockTreeJob)go every(5*time.Second, model.SyncDataJob)go every(2*time.Hour, model.StatJob)go every(2*time.Hour, model.RefreshCheckJob)diff --git a/kernel/model/index_fix.go b/kernel/model/index_fix.goindex 88d892ca7e..a95209e1b8 100644--- a/kernel/model/index_fix.go+++ b/kernel/model/index_fix.go@@ -108,7 +108,7 @@ func autoFixIndex() {redundantPaths := treenode.GetRedundantPaths(box.ID, paths)for _, p := range redundantPaths {- treenode.RemoveBlockTreesByPath(p)+ treenode.RemoveBlockTreesByPath(box.ID, p)}missingPaths := treenode.GetNotExistPaths(box.ID, paths)diff --git a/kernel/treenode/blocktree.go b/kernel/treenode/blocktree.goindex 20fa10809c..5aa0a7d2f2 100644--- a/kernel/treenode/blocktree.go+++ b/kernel/treenode/blocktree.go@@ -36,7 +36,7 @@ import ("github.com/vmihailenco/msgpack/v5")-var blockTrees = sync.Map{}+var blockTrees = &sync.Map{}type btSlice struct {data map[string]*BlockTree@@ -269,13 +269,13 @@ func RemoveBlockTreesByRootID(rootID string) {}}-func RemoveBlockTreesByPath(path string) {+func RemoveBlockTreesByPath(boxID, path string) {var ids []stringblockTrees.Range(func(key, value interface{}) bool {slice := value.(*btSlice)slice.m.Lock()for _, b := range slice.data {- if b.Path == path {+ if b.Path == path && b.BoxID == boxID {ids = append(ids, b.RootID)}}@@ -386,8 +386,15 @@ func IndexBlockTree(tree *parse.Tree) {}slice := val.(*btSlice)slice.m.Lock()- slice.data[n.ID] = &BlockTree{ID: n.ID, ParentID: parentID, RootID: tree.ID, BoxID: tree.Box, Path: tree.Path, HPath: tree.HPath, Updated: n.IALAttr("updated"), Type: TypeAbbr(n.Type.String())}- slice.changed = time.Now()+ if bt := slice.data[n.ID]; nil != bt {+ if bt.Updated != n.IALAttr("updated") {+ slice.data[n.ID] = &BlockTree{ID: n.ID, ParentID: parentID, RootID: tree.ID, BoxID: tree.Box, Path: tree.Path, HPath: tree.HPath, Updated: n.IALAttr("updated"), Type: TypeAbbr(n.Type.String())}+ slice.changed = time.Now()+ }+ } else {+ slice.data[n.ID] = &BlockTree{ID: n.ID, ParentID: parentID, RootID: tree.ID, BoxID: tree.Box, Path: tree.Path, HPath: tree.HPath, Updated: n.IALAttr("updated"), Type: TypeAbbr(n.Type.String())}+ slice.changed = time.Now()+ }slice.m.Unlock()return ast.WalkContinue})@@ -401,6 +408,7 @@ func InitBlockTree(force bool) {if nil != err {logging.LogErrorf("remove blocktree file failed: %s", err)}+ blockTrees = &sync.Map{}return}@@ -485,7 +493,7 @@ func SaveBlockTree(force bool) {key := arg.(map[string]interface{})["key"].(string)slice := arg.(map[string]interface{})["value"].(*btSlice)- if !force && (slice.changed.IsZero() || slice.changed.After(start.Add(-7*time.Second))) {+ if !force && slice.changed.IsZero() {return}@@ -508,16 +516,22 @@ func SaveBlockTree(force bool) {size += uint64(len(data))})+ var count intblockTrees.Range(func(key, value interface{}) bool {slice := value.(*btSlice)- if !force && (slice.changed.IsZero() || slice.changed.After(start.Add(-7*time.Second))) {+ if !force && slice.changed.IsZero() {return true}+ count+++waitGroup.Add(1)p.Invoke(map[string]interface{}{"key": key, "value": value})return true})+ if 0 < count {+ logging.LogInfof("wrote block trees [%d]", count)+ }waitGroup.Wait()p.Release()