Просмотр исходного кода

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

Daniel 1 год назад
Родитель
Сommit
16c665bfa7
4 измененных файлов с 16 добавлено и 12 удалено
  1. 3 2
      kernel/model/box.go
  2. 2 2
      kernel/model/tree.go
  3. 4 8
      kernel/task/queue.go
  4. 7 0
      kernel/treenode/blocktree.go

+ 3 - 2
kernel/model/box.go

@@ -506,14 +506,15 @@ func FullReindex() {
 }
 }
 
 
 func fullReindex() {
 func fullReindex() {
-	util.PushMsg(Conf.Language(35), 7*1000)
+	util.PushEndlessProgress(Conf.language(35))
+	defer util.PushClearProgress()
+
 	WaitForWritingFiles()
 	WaitForWritingFiles()
 
 
 	if err := sql.InitDatabase(true); nil != err {
 	if err := sql.InitDatabase(true); nil != err {
 		os.Exit(logging.ExitCodeReadOnlyDatabase)
 		os.Exit(logging.ExitCodeReadOnlyDatabase)
 		return
 		return
 	}
 	}
-	treenode.InitBlockTree(true)
 
 
 	sql.IndexIgnoreCached = false
 	sql.IndexIgnoreCached = false
 	openedBoxes := Conf.GetOpenedBoxes()
 	openedBoxes := Conf.GetOpenedBoxes()

+ 2 - 2
kernel/model/tree.go

@@ -162,7 +162,7 @@ func LoadTreeByBlockIDWithReindex(id string) (ret *parse.Tree, err error) {
 
 
 	bt := treenode.GetBlockTree(id)
 	bt := treenode.GetBlockTree(id)
 	if nil == bt {
 	if nil == bt {
-		if task.Contain(task.DatabaseIndex, task.DatabaseIndexFull) {
+		if task.ContainIndexTask() {
 			err = ErrIndexing
 			err = ErrIndexing
 			return
 			return
 		}
 		}
@@ -187,7 +187,7 @@ func LoadTreeByBlockID(id string) (ret *parse.Tree, err error) {
 
 
 	bt := treenode.GetBlockTree(id)
 	bt := treenode.GetBlockTree(id)
 	if nil == bt {
 	if nil == bt {
-		if task.Contain(task.DatabaseIndex, task.DatabaseIndexFull) {
+		if task.ContainIndexTask() {
 			err = ErrIndexing
 			err = ErrIndexing
 			return
 			return
 		}
 		}

+ 4 - 8
kernel/task/queue.go

@@ -115,17 +115,13 @@ var uniqueActions = []string{
 	AssetContentDatabaseIndexCommit,
 	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
 			return true
 		}
 		}
 	}
 	}
-	queueLock.Unlock()
 	return false
 	return false
 }
 }
 
 

+ 7 - 0
kernel/treenode/blocktree.go

@@ -31,6 +31,7 @@ import (
 	"github.com/panjf2000/ants/v2"
 	"github.com/panjf2000/ants/v2"
 	util2 "github.com/siyuan-note/dejavu/util"
 	util2 "github.com/siyuan-note/dejavu/util"
 	"github.com/siyuan-note/logging"
 	"github.com/siyuan-note/logging"
+	"github.com/siyuan-note/siyuan/kernel/task"
 	"github.com/siyuan-note/siyuan/kernel/util"
 	"github.com/siyuan-note/siyuan/kernel/util"
 	"github.com/vmihailenco/msgpack/v5"
 	"github.com/vmihailenco/msgpack/v5"
 )
 )
@@ -504,6 +505,12 @@ func SaveBlockTree(force bool) {
 	blockTreeLock.Lock()
 	blockTreeLock.Lock()
 	defer blockTreeLock.Unlock()
 	defer blockTreeLock.Unlock()
 
 
+	if task.ContainIndexTask() {
+		//logging.LogInfof("skip saving block tree because indexing")
+		return
+	}
+	//logging.LogInfof("saving block tree")
+
 	start := time.Now()
 	start := time.Now()
 	if err := os.MkdirAll(util.BlockTreePath, 0755); nil != err {
 	if err := os.MkdirAll(util.BlockTreePath, 0755); nil != err {
 		logging.LogErrorf("create block tree dir [%s] failed: %s", util.BlockTreePath, err)
 		logging.LogErrorf("create block tree dir [%s] failed: %s", util.BlockTreePath, err)