🎨 Reindex notebook and reload UI after data sync if notebook conf changed https://github.com/siyuan-note/siyuan/issues/11850

This commit is contained in:
Daniel 2024-06-28 11:41:57 +08:00
parent 1dfdffa5a7
commit 222635c5a1
No known key found for this signature in database
GPG key ID: 86211BA83DF03017
2 changed files with 24 additions and 4 deletions

View file

@ -1312,11 +1312,11 @@ func GetFullHPathByID(id string) (hPath string, err error) {
}
box := Conf.Box(tree.Box)
var boxName string
if nil != box {
boxName = box.Name
if nil == box {
err = ErrBoxNotFound
return
}
hPath = boxName + tree.HPath
hPath = box.Name + tree.HPath
return
}

View file

@ -1413,6 +1413,7 @@ func processSyncMergeResult(exit, byHand bool, mergeResult *dejavu.MergeResult,
// 可能需要重新加载部分功能
var needReloadFlashcard, needReloadOcrTexts, needReloadPlugin bool
upsertPluginSet := hashset.New()
needUnindexBoxes, needIndexBoxes := map[string]bool{}, map[string]bool{}
for _, file := range mergeResult.Upserts {
upserts = append(upserts, file.Path)
if strings.HasPrefix(file.Path, "/storage/riff/") {
@ -1425,6 +1426,9 @@ func processSyncMergeResult(exit, byHand bool, mergeResult *dejavu.MergeResult,
if strings.HasSuffix(file.Path, "/.siyuan/conf.json") {
needReloadFiletree = true
boxID := strings.TrimSuffix(strings.TrimPrefix(file.Path, "/"), "/.siyuan/conf.json")
needUnindexBoxes[boxID] = true
needIndexBoxes[boxID] = true
}
if strings.HasPrefix(file.Path, "/storage/petal/") {
@ -1456,6 +1460,8 @@ func processSyncMergeResult(exit, byHand bool, mergeResult *dejavu.MergeResult,
if strings.HasSuffix(file.Path, "/.siyuan/conf.json") {
needReloadFiletree = true
boxID := strings.TrimSuffix(strings.TrimPrefix(file.Path, "/"), "/.siyuan/conf.json")
needUnindexBoxes[boxID] = true
}
if strings.HasPrefix(file.Path, "/storage/petal/") {
@ -1509,6 +1515,20 @@ func processSyncMergeResult(exit, byHand bool, mergeResult *dejavu.MergeResult,
return
}
for boxID := range needUnindexBoxes {
if box := Conf.GetBox(boxID); nil != box {
box.Unindex()
}
}
for boxID := range needIndexBoxes {
if box := Conf.GetBox(boxID); nil != box {
box.Index()
}
}
if 0 < len(needUnindexBoxes) || 0 < len(needIndexBoxes) {
util.ReloadUI()
}
upsertRootIDs, removeRootIDs := incReindex(upserts, removes)
go func() {
util.WaitForUILoaded()