Skip to content

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

:art: Partially refresh the interface after data synchronization https://github.com/siyuan-note/siyuan/issues/8098

Liang Ding125700d07511
diff --git a/kernel/model/box.go b/kernel/model/box.go
index f8c3b0923d..e2f79e1312 100644
--- a/kernel/model/box.go
+++ b/kernel/model/box.go
@@ -478,10 +478,6 @@ func genTreeID(tree *parse.Tree) {
return
}
-func ReloadUI() {
- task.AppendTask(task.ReloadUI, util.ReloadUI)
-}
-
func FullReindex() {
task.AppendTask(task.DatabaseIndexFull, fullReindex)
task.AppendTask(task.DatabaseIndexRef, IndexRefs)
diff --git a/kernel/model/repository.go b/kernel/model/repository.go
index 552bc6d576..b5513013b7 100644
--- a/kernel/model/repository.go
+++ b/kernel/model/repository.go
@@ -1053,8 +1053,6 @@ func bootSyncRepo() (err error) {
if 0 < len(fetchedFiles) {
go func() {
- util.WaitForUILoaded() // 等待一段时间后前端完成界面初始化后再同步,因为需要推送消息
-
syncErr := syncRepo(false, false)
if nil != err {
logging.LogErrorf("boot background sync repo failed: %s", syncErr)
@@ -1239,33 +1237,35 @@ func processSyncMergeResult(exit, byHand bool, start time.Time, mergeResult *dej
return
}
- incReindex(upserts, removes)
- if !exit {
- ReloadUI()
+ if exit { // 退出时同步不用推送事件
+ return
}
+ upsertRootIDs, removeRootIDs := incReindex(upserts, removes)
elapsed := time.Since(start)
- if !exit {
- go func() {
- time.Sleep(2 * time.Second)
- util.PushStatusBar(fmt.Sprintf(Conf.Language(149), elapsed.Seconds()))
-
- if 0 < len(mergeResult.Conflicts) {
- syConflict := false
- for _, file := range mergeResult.Conflicts {
- if strings.HasSuffix(file.Path, ".sy") {
- syConflict = true
- break
- }
- }
+ go func() {
+ util.WaitForUILoaded()
+ util.BroadcastByType("main", "syncMergeResult", 0, "",
+ map[string]interface{}{"upsertRootIDs": upsertRootIDs, "removeRootIDs": removeRootIDs})
+
+ time.Sleep(2 * time.Second)
+ util.PushStatusBar(fmt.Sprintf(Conf.Language(149), elapsed.Seconds()))
- if syConflict {
- // 数据同步发生冲突时在界面上进行提醒 https://github.com/siyuan-note/siyuan/issues/7332
- util.PushMsg(Conf.Language(108), 7000)
+ if 0 < len(mergeResult.Conflicts) {
+ syConflict := false
+ for _, file := range mergeResult.Conflicts {
+ if strings.HasSuffix(file.Path, ".sy") {
+ syConflict = true
+ break
}
}
- }()
- }
+
+ if syConflict {
+ // 数据同步发生冲突时在界面上进行提醒 https://github.com/siyuan-note/siyuan/issues/7332
+ util.PushMsg(Conf.Language(108), 7000)
+ }
+ }
+ }()
}
func logSyncMergeResult(mergeResult *dejavu.MergeResult) {
diff --git a/kernel/model/sync.go b/kernel/model/sync.go
index 97cb315cf3..3719c372a0 100644
--- a/kernel/model/sync.go
+++ b/kernel/model/sync.go
@@ -260,7 +260,7 @@ func checkSync(boot, exit, byHand bool) bool {
}
// incReindex 增量重建索引。
-func incReindex(upserts, removes []string) {
+func incReindex(upserts, removes []string) (upsertRootIDs, removeRootIDs []string) {
util.IncBootProgress(3, "Sync reindexing...")
msg := fmt.Sprintf(Conf.Language(35))
util.PushStatusBar(msg)
@@ -274,6 +274,7 @@ func incReindex(upserts, removes []string) {
}
id := strings.TrimSuffix(filepath.Base(removeFile), ".sy")
+ removeRootIDs = append(removeRootIDs, id)
block := treenode.GetBlockTree(id)
if nil != block {
msg = fmt.Sprintf(Conf.Language(39), block.RootID)
@@ -316,7 +317,9 @@ func incReindex(upserts, removes []string) {
}
treenode.IndexBlockTree(tree)
sql.UpsertTreeQueue(tree)
+ upsertRootIDs = append(upsertRootIDs, tree.Root.ID)
}
+ return
}
func SetCloudSyncDir(name string) {