Skip to content

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

:art: `tree not found` appears when rebuilding index https://github.com/siyuan-note/siyuan/issues/11036

Daniel16c665bfa738
diff --git a/kernel/model/box.go b/kernel/model/box.go
index 450d9014b9..8b2ad4d455 100644
--- a/kernel/model/box.go
+++ b/kernel/model/box.go
@@ -506,14 +506,15 @@ func FullReindex() {
}
func fullReindex() {
- util.PushMsg(Conf.Language(35), 7*1000)
+ util.PushEndlessProgress(Conf.language(35))
+ defer util.PushClearProgress()
+
WaitForWritingFiles()
if err := sql.InitDatabase(true); nil != err {
os.Exit(logging.ExitCodeReadOnlyDatabase)
return
}
- treenode.InitBlockTree(true)
sql.IndexIgnoreCached = false
openedBoxes := Conf.GetOpenedBoxes()
diff --git a/kernel/model/tree.go b/kernel/model/tree.go
index db9d62d1d0..a83e09a066 100644
--- a/kernel/model/tree.go
+++ b/kernel/model/tree.go
@@ -162,7 +162,7 @@ func LoadTreeByBlockIDWithReindex(id string) (ret *parse.Tree, err error) {
bt := treenode.GetBlockTree(id)
if nil == bt {
- if task.Contain(task.DatabaseIndex, task.DatabaseIndexFull) {
+ if task.ContainIndexTask() {
err = ErrIndexing
return
}
@@ -187,7 +187,7 @@ func LoadTreeByBlockID(id string) (ret *parse.Tree, err error) {
bt := treenode.GetBlockTree(id)
if nil == bt {
- if task.Contain(task.DatabaseIndex, task.DatabaseIndexFull) {
+ if task.ContainIndexTask() {
err = ErrIndexing
return
}
diff --git a/kernel/task/queue.go b/kernel/task/queue.go
index 4eba696ba5..2baf64609e 100644
--- a/kernel/task/queue.go
+++ b/kernel/task/queue.go
@@ -115,17 +115,13 @@ var uniqueActions = []string{
AssetContentDatabaseIndexCommit,
}
-func Contain(action string, moreActions ...string) bool {
- actions := append(moreActions, action)
- actions = gulu.Str.RemoveDuplicatedElem(actions)
-
- queueLock.Lock()
- for _, task := range taskQueue {
- if gulu.Str.Contains(task.Action, actions) {
+func ContainIndexTask() bool {
+ actions := getCurrentActions()
+ for _, action := range actions {
+ if gulu.Str.Contains(action, []string{DatabaseIndexFull, DatabaseIndex}) {
return true
}
}
- queueLock.Unlock()
return false
}
diff --git a/kernel/treenode/blocktree.go b/kernel/treenode/blocktree.go
index 536a141c5f..823036acc8 100644
--- a/kernel/treenode/blocktree.go
+++ b/kernel/treenode/blocktree.go
@@ -31,6 +31,7 @@ import (
"github.com/panjf2000/ants/v2"
util2 "github.com/siyuan-note/dejavu/util"
"github.com/siyuan-note/logging"
+ "github.com/siyuan-note/siyuan/kernel/task"
"github.com/siyuan-note/siyuan/kernel/util"
"github.com/vmihailenco/msgpack/v5"
)
@@ -504,6 +505,12 @@ func SaveBlockTree(force bool) {
blockTreeLock.Lock()
defer blockTreeLock.Unlock()
+ if task.ContainIndexTask() {
+ //logging.LogInfof("skip saving block tree because indexing")
+ return
+ }
+ //logging.LogInfof("saving block tree")
+
start := time.Now()
if err := os.MkdirAll(util.BlockTreePath, 0755); nil != err {
logging.LogErrorf("create block tree dir [%s] failed: %s", util.BlockTreePath, err)