Skip to content

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

:art: 数据快照 https://github.com/siyuan-note/siyuan/issues/5159

Liang Ding70adf3860ee1
diff --git a/kernel/go.mod b/kernel/go.mod
index 4b96a6344c..68a12c021b 100644
--- a/kernel/go.mod
+++ b/kernel/go.mod
@@ -40,7 +40,7 @@ require (
github.com/patrickmn/go-cache v2.1.0+incompatible
github.com/qiniu/go-sdk/v7 v7.13.0
github.com/radovskyb/watcher v1.0.7
- github.com/siyuan-note/dejavu v0.0.0-20220614075107-2c74319dce59
+ github.com/siyuan-note/dejavu v0.0.0-20220614100921-f1d318f3dd6b
github.com/siyuan-note/encryption v0.0.0-20220612074546-f1dd94fe8676
github.com/vmihailenco/msgpack/v5 v5.3.5
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673
diff --git a/kernel/go.sum b/kernel/go.sum
index b109c08c3a..2189b41d4b 100644
--- a/kernel/go.sum
+++ b/kernel/go.sum
@@ -419,8 +419,8 @@ github.com/shurcooL/httpfs v0.0.0-20190707220628-8d4bc4ba7749/go.mod h1:ZY1cvUeJ
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
github.com/shurcooL/vfsgen v0.0.0-20200824052919-0d455de96546/go.mod h1:TrYk7fJVaAttu97ZZKrO9UbRa8izdowaMIZcxYMbVaw=
github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
-github.com/siyuan-note/dejavu v0.0.0-20220614034547-ec837e2de9a3 h1:z5QeeeMNXvtuVNue7llW9f5DNe01ir/PRJIFNKFRTJc=
-github.com/siyuan-note/dejavu v0.0.0-20220614034547-ec837e2de9a3/go.mod h1:Oa/Y6fvTUCg8h9/t6GNWXiu8T7aQri/ZvyDRygnlikI=
+github.com/siyuan-note/dejavu v0.0.0-20220614100921-f1d318f3dd6b h1:GyLlhQQsgfVFzyWB+OB1wCRlyzBhI4EkczC0YK9cRHc=
+github.com/siyuan-note/dejavu v0.0.0-20220614100921-f1d318f3dd6b/go.mod h1:Oa/Y6fvTUCg8h9/t6GNWXiu8T7aQri/ZvyDRygnlikI=
github.com/siyuan-note/encryption v0.0.0-20220612074546-f1dd94fe8676 h1:QB9TjJQFhXhZ6dAtPpY02DlzHAQm1C+WqZq6OadG8mI=
github.com/siyuan-note/encryption v0.0.0-20220612074546-f1dd94fe8676/go.mod h1:H8fyqqAbp9XreANjeSbc72zEdFfKTXYN34tc1TjZwtw=
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
diff --git a/kernel/model/repository.go b/kernel/model/repository.go
index 82e6079c2a..ce6207d73f 100644
--- a/kernel/model/repository.go
+++ b/kernel/model/repository.go
@@ -21,6 +21,7 @@ import (
"encoding/hex"
"errors"
"os"
+ "time"
"github.com/88250/gulu"
"github.com/siyuan-note/dejavu"
@@ -45,6 +46,12 @@ func GetRepoIndexLogs(page int) (logs []*dejavu.Log, pageCount, totalCount int,
page-- // 从 0 开始
logs, pageCount, totalCount, err = repo.GetIndexLogs(page, 32)
if nil != err {
+ if dejavu.ErrNotFoundIndex == err {
+ logs = []*dejavu.Log{}
+ err = nil
+ return
+ }
+
util.LogErrorf("get repo index logs failed: %s", err)
return
}
@@ -124,11 +131,31 @@ func CheckoutRepo(id string) (err error) {
return
}
- syncLock.Lock()
- defer syncLock.Unlock()
filesys.ReleaseAllFileLocks()
+ writingDataLock.Lock()
+ defer writingDataLock.Unlock()
+
+ CloseWatchAssets()
+ defer WatchAssets()
+
+ // 恢复快照时自动暂停同步,避免刚刚恢复后的数据又被同步覆盖
+ syncEnabled := Conf.Sync.Enabled
+ Conf.Sync.Enabled = false
+ Conf.Save()
+
err = repo.Checkout(id, util.PushEndlessProgress, checkoutCallbacks)
- util.PushClearProgress()
+ if nil != err {
+ util.PushClearProgress()
+ return
+ }
+
+ RefreshFileTree()
+ if syncEnabled {
+ func() {
+ time.Sleep(5 * time.Second)
+ util.PushMsg(Conf.Language(134), 0)
+ }()
+ }
return
}
@@ -163,9 +190,9 @@ func IndexRepo(memo string) (err error) {
}
WaitForWritingFiles()
- syncLock.Lock()
- defer syncLock.Unlock()
filesys.ReleaseAllFileLocks()
+ writingDataLock.Lock()
+ defer writingDataLock.Unlock()
_, err = repo.Index(memo, util.PushEndlessProgress, indexCallbacks)
util.PushClearProgress()
return