Skip to content

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

:art: Data sync supports the multi-kernel online perception https://github.com/siyuan-note/siyuan/issues/8518

Daniel5e041d901703
diff --git a/kernel/go.mod b/kernel/go.mod
index 878d77ca35..edf15c4d42 100644
--- a/kernel/go.mod
+++ b/kernel/go.mod
@@ -31,6 +31,7 @@ require (
github.com/go-ole/go-ole v1.2.6
github.com/goccy/go-json v0.10.2
github.com/gofrs/flock v0.8.1
+ github.com/gorilla/websocket v1.5.0
github.com/imroc/req/v3 v3.35.2
github.com/jinzhu/copier v0.3.5
github.com/json-iterator/go v1.1.12
@@ -44,7 +45,7 @@ require (
github.com/radovskyb/watcher v1.0.7
github.com/sashabaranov/go-openai v1.9.5
github.com/shirou/gopsutil/v3 v3.23.5
- github.com/siyuan-note/dejavu v0.0.0-20230610031820-8b10ca0d32b9
+ github.com/siyuan-note/dejavu v0.0.0-20230612120039-bba808ca7649
github.com/siyuan-note/encryption v0.0.0-20220713091850-5ecd92177b75
github.com/siyuan-note/eventbus v0.0.0-20230216103454-41885eac6c2b
github.com/siyuan-note/filelock v0.0.0-20230523004741-d9121740f638
@@ -89,7 +90,6 @@ require (
github.com/gorilla/css v1.0.0 // indirect
github.com/gorilla/securecookie v1.1.1 // indirect
github.com/gorilla/sessions v1.2.1 // indirect
- github.com/gorilla/websocket v1.5.0 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/hhrutter/lzw v1.0.0 // indirect
diff --git a/kernel/go.sum b/kernel/go.sum
index 8d7c83852a..c20a8d82f2 100644
--- a/kernel/go.sum
+++ b/kernel/go.sum
@@ -281,8 +281,8 @@ github.com/shopspring/decimal v1.3.1 h1:2Usl1nmF/WZucqkFZhnfFYxxxu8LG21F6nPQBE5g
github.com/shopspring/decimal v1.3.1/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o=
github.com/shurcooL/gofontwoff v0.0.0-20181114050219-180f79e6909d h1:lvCTyBbr36+tqMccdGMwuEU+hjux/zL6xSmf5S9ITaA=
github.com/shurcooL/gofontwoff v0.0.0-20181114050219-180f79e6909d/go.mod h1:05UtEgK5zq39gLST6uB0cf3NEHjETfB4Fgr3Gx5R9Vw=
-github.com/siyuan-note/dejavu v0.0.0-20230610031820-8b10ca0d32b9 h1:zG/c1Bhx4/rUxcPtr3O23WhbapN5R2ny8j1AuLdrV6k=
-github.com/siyuan-note/dejavu v0.0.0-20230610031820-8b10ca0d32b9/go.mod h1:hqZGaLRW8MNQiypk+RsRWMjjCHx4i+RSoZiK62q9m0Q=
+github.com/siyuan-note/dejavu v0.0.0-20230612120039-bba808ca7649 h1:MpzA21Jp0ofPJJxP8DwQGVXU2BGGV/blBFk130Du1Mw=
+github.com/siyuan-note/dejavu v0.0.0-20230612120039-bba808ca7649/go.mod h1:hqZGaLRW8MNQiypk+RsRWMjjCHx4i+RSoZiK62q9m0Q=
github.com/siyuan-note/encryption v0.0.0-20220713091850-5ecd92177b75 h1:Bi7/7f29LW+Fm0cHc0J1NO1cZqyJwljSWVmfOqVZgaE=
github.com/siyuan-note/encryption v0.0.0-20220713091850-5ecd92177b75/go.mod h1:H8fyqqAbp9XreANjeSbc72zEdFfKTXYN34tc1TjZwtw=
github.com/siyuan-note/eventbus v0.0.0-20230216103454-41885eac6c2b h1:828lTUW2C0uNiolODqoACu7J8sDUzswD4Xo04mUombg=
diff --git a/kernel/model/repository.go b/kernel/model/repository.go
index 99e96e9fdf..bec179340b 100644
--- a/kernel/model/repository.go
+++ b/kernel/model/repository.go
@@ -1092,7 +1092,7 @@ func bootSyncRepo() (err error) {
if 0 < len(fetchedFiles) {
go func() {
- syncErr := syncRepo(false, false)
+ _, syncErr := syncRepo(false, false)
if nil != err {
logging.LogErrorf("boot background sync repo failed: %s", syncErr)
return
@@ -1102,7 +1102,7 @@ func bootSyncRepo() (err error) {
return
}
-func syncRepo(exit, byHand bool) (err error) {
+func syncRepo(exit, byHand bool) (mergeResult *dejavu.MergeResult, err error) {
if 1 > len(Conf.Repo.Key) {
autoSyncErrCount++
planSyncAfter(fixSyncInterval)
diff --git a/kernel/model/sync.go b/kernel/model/sync.go
index 5f9f4c86cd..4f1d74239b 100644
--- a/kernel/model/sync.go
+++ b/kernel/model/sync.go
@@ -180,7 +180,7 @@ func syncData(exit, byHand, byWebSocket bool) {
now := util.CurrentTimeMillis()
Conf.Sync.Synced = now
- err := syncRepo(exit, byHand)
+ mergeResult, err := syncRepo(exit, byHand)
code := 1
if nil != err {
code = 2
@@ -192,7 +192,7 @@ func syncData(exit, byHand, byWebSocket bool) {
connectSyncWebSocket()
}
- if 1 == Conf.Sync.Mode && !byWebSocket && nil != webSocketConn && Conf.Sync.Perception {
+ if 1 == Conf.Sync.Mode && !byWebSocket && nil != webSocketConn && Conf.Sync.Perception && mergeResult.DataChanged() {
// 如果处于自动同步模式且不是又 WS 触发的同步,则通知其他设备上的内核进行同步
request := map[string]interface{}{
"cmd": "synced",