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

This commit is contained in:
Daniel 2024-04-14 22:16:46 +08:00
parent 1ae39777a6
commit 16c665bfa7
No known key found for this signature in database
GPG Key ID: 86211BA83DF03017
4 changed files with 16 additions and 12 deletions

View File

@ -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()

View File

@ -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
} }

View File

@ -115,17 +115,13 @@ var uniqueActions = []string{
AssetContentDatabaseIndexCommit, AssetContentDatabaseIndexCommit,
} }
func Contain(action string, moreActions ...string) bool { func ContainIndexTask() bool {
actions := append(moreActions, action) actions := getCurrentActions()
actions = gulu.Str.RemoveDuplicatedElem(actions) for _, action := range actions {
if gulu.Str.Contains(action, []string{DatabaseIndexFull, DatabaseIndex}) {
queueLock.Lock()
for _, task := range taskQueue {
if gulu.Str.Contains(task.Action, actions) {
return true return true
} }
} }
queueLock.Unlock()
return false return false
} }

View File

@ -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)