An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:bug: 重复执行 `重建索引` 导致内核崩溃 https://github.com/siyuan-note/siyuan/issues/7238
Liang Dingc7d51d2e6cd4
diff --git a/kernel/treenode/blocktree.go b/kernel/treenode/blocktree.goindex 43da32297b..a4a6b5950b 100644--- a/kernel/treenode/blocktree.go+++ b/kernel/treenode/blocktree.go@@ -391,15 +391,11 @@ func SaveBlockTree(force bool) {os.MkdirAll(util.BlockTreePath, 0755)size := uint64(0)- poolSize := runtime.NumCPU()- waitGroup := &sync.WaitGroup{}- p, _ := ants.NewPoolWithFunc(poolSize, func(arg interface{}) {- defer waitGroup.Done()-- key := arg.(map[string]interface{})["key"].(string)- slice := arg.(map[string]interface{})["value"].(*btSlice)+ var count int+ blockTrees.Range(func(key, value interface{}) bool {+ slice := value.(*btSlice)if !force && slice.changed.IsZero() {- return+ return true}slice.m.Lock()@@ -407,40 +403,26 @@ func SaveBlockTree(force bool) {if nil != err {logging.LogErrorf("marshal block tree failed: %s", err)os.Exit(util.ExitCodeBlockTreeErr)- return+ return false}slice.m.Unlock()- p := filepath.Join(util.BlockTreePath, key) + ".msgpack"+ p := filepath.Join(util.BlockTreePath, key.(string)) + ".msgpack"if err = gulu.File.WriteFileSafer(p, data, 0644); nil != err {logging.LogErrorf("write block tree failed: %s", err)os.Exit(util.ExitCodeBlockTreeErr)- return+ return false}+slice.changed = time.Time{}size += uint64(len(data))- })-- var count int- blockTrees.Range(func(key, value interface{}) bool {- slice := value.(*btSlice)- 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)+ logging.LogInfof("wrote block trees [%d]", count)}- waitGroup.Wait()- p.Release()-- runtime.GC()elapsed := time.Since(start).Seconds()if 2 < elapsed {logging.LogWarnf("save block tree [size=%s] to [%s], elapsed [%.2fs]", humanize.Bytes(size), util.BlockTreePath, elapsed)