浏览代码

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

Daniel 1 年之前
父节点
当前提交
222635c5a1
共有 2 个文件被更改,包括 24 次插入4 次删除
  1. 4 4
      kernel/model/file.go
  2. 20 0
      kernel/model/repository.go

+ 4 - 4
kernel/model/file.go

@@ -1312,11 +1312,11 @@ func GetFullHPathByID(id string) (hPath string, err error) {
 	}
 	}
 
 
 	box := Conf.Box(tree.Box)
 	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
 	return
 }
 }
 
 

+ 20 - 0
kernel/model/repository.go

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