Skip to content

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

:art: Sync repo

Liang Ding8a587c23e277
diff --git a/kernel/go.mod b/kernel/go.mod
index 8364a12196..c39ef6165e 100644
--- a/kernel/go.mod
+++ b/kernel/go.mod
@@ -40,7 +40,7 @@ require (
github.com/qiniu/go-sdk/v7 v7.13.0
github.com/radovskyb/watcher v1.0.7
github.com/sabhiram/go-gitignore v0.0.0-20210923224102-525f6e181f06
- github.com/siyuan-note/dejavu v0.0.0-20220703035113-18e14b337842
+ github.com/siyuan-note/dejavu v0.0.0-20220703090706-398001e73204
github.com/siyuan-note/encryption v0.0.0-20220612074546-f1dd94fe8676
github.com/siyuan-note/eventbus v0.0.0-20220624162334-ca7c06dc771f
github.com/siyuan-note/filelock v0.0.0-20220616063212-74cfba0754ee
diff --git a/kernel/go.sum b/kernel/go.sum
index bacc4a8816..077b806a2d 100644
--- a/kernel/go.sum
+++ b/kernel/go.sum
@@ -421,8 +421,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-20220703035113-18e14b337842 h1:mQHKAy22FDi5J3R4xLvBbX7X/ofxq8pZ8qEwW6ZYuE8=
-github.com/siyuan-note/dejavu v0.0.0-20220703035113-18e14b337842/go.mod h1:0t+TpAdsrrv+6LkhDlJY2Gl92CQexgp8KWOBp5Ah9kU=
+github.com/siyuan-note/dejavu v0.0.0-20220703090706-398001e73204 h1:B7K+65InyNtBr+2NSRt2sxViOAhCUWrA6ci5/WF5R+I=
+github.com/siyuan-note/dejavu v0.0.0-20220703090706-398001e73204/go.mod h1:0t+TpAdsrrv+6LkhDlJY2Gl92CQexgp8KWOBp5Ah9kU=
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/siyuan-note/eventbus v0.0.0-20220624162334-ca7c06dc771f h1:JMobMNZ7AqaKKyEK+WeWFhix/2TDQXgPZDajU00IybU=
diff --git a/kernel/model/history.go b/kernel/model/history.go
index 119c88bfdd..1818c3b34e 100644
--- a/kernel/model/history.go
+++ b/kernel/model/history.go
@@ -54,7 +54,7 @@ func generateDocHistory() {
box.generateDocHistory0()
}
- historyDir := filepath.Join(util.WorkspaceDir, "history")
+ historyDir := util.HistoryDir
clearOutdatedHistoryDir(historyDir)
// 以下部分是老版本的清理逻辑,暂时保留
@@ -79,7 +79,7 @@ func ChangeHistoryTick(minutes int) {
}
func ClearWorkspaceHistory() (err error) {
- historyDir := filepath.Join(util.WorkspaceDir, "history")
+ historyDir := util.HistoryDir
if gulu.File.IsDir(historyDir) {
if err = os.RemoveAll(historyDir); nil != err {
util.LogErrorf("remove workspace history dir [%s] failed: %s", historyDir, err)
@@ -257,7 +257,7 @@ const maxHistory = 32
func GetDocHistory(boxID string) (ret []*History, err error) {
ret = []*History{}
- historyDir := filepath.Join(util.WorkspaceDir, "history")
+ historyDir := util.HistoryDir
if !gulu.File.IsDir(historyDir) {
return
}
@@ -342,7 +342,7 @@ func GetDocHistory(boxID string) (ret []*History, err error) {
func GetNotebookHistory() (ret []*History, err error) {
ret = []*History{}
- historyDir := filepath.Join(util.WorkspaceDir, "history")
+ historyDir := util.HistoryDir
if !gulu.File.IsDir(historyDir) {
return
}
@@ -402,7 +402,7 @@ func GetNotebookHistory() (ret []*History, err error) {
func GetAssetsHistory() (ret []*History, err error) {
ret = []*History{}
- historyDir := filepath.Join(util.WorkspaceDir, "history")
+ historyDir := util.HistoryDir
if !gulu.File.IsDir(historyDir) {
return
}
diff --git a/kernel/model/repository.go b/kernel/model/repository.go
index 6440bc9472..c69b588a68 100644
--- a/kernel/model/repository.go
+++ b/kernel/model/repository.go
@@ -316,7 +316,7 @@ func syncRepo(byHand bool) {
Server: util.AliyunServer,
}
syncContext := map[string]interface{}{CtxPushMsg: CtxPushMsgToStatusBar}
- latest, mergeUpserts, mergeRemoves, err := repo.Sync(cloudInfo, syncContext)
+ latest, mergeUpserts, mergeRemoves, _, err := repo.Sync(cloudInfo, syncContext)
elapsed := time.Since(start)
util.LogInfof("sync data repo elapsed [%.2fs], latest [%s]", elapsed.Seconds(), latest.ID)
@@ -338,11 +338,11 @@ func syncRepo(byHand bool) {
syncSameCount = 5
}
if !byHand {
- after := time.Minute * time.Duration(int(math.Pow(2, float64(syncSameCount))))
- if fixSyncInterval.Minutes() > after.Minutes() {
- after = time.Minute * 8
+ delay := time.Minute * time.Duration(int(math.Pow(2, float64(syncSameCount))))
+ if fixSyncInterval.Minutes() > delay.Minutes() {
+ delay = time.Minute * 8
}
- planSyncAfter(after)
+ planSyncAfter(delay)
}
return
}
@@ -371,7 +371,7 @@ func syncRepo(byHand bool) {
func newRepository() (ret *dejavu.Repo, err error) {
ignoreLines := getIgnoreLines()
ignoreLines = append(ignoreLines, "/.siyuan/conf.json") // 忽略旧版同步配置
- ret, err = dejavu.NewRepo(util.DataDir, util.RepoDir, Conf.Repo.Key, ignoreLines)
+ ret, err = dejavu.NewRepo(util.DataDir, util.RepoDir, util.HistoryDir, util.TempDir, Conf.Repo.Key, ignoreLines)
if nil != err {
util.LogErrorf("init data repository failed: %s", err)
}
diff --git a/kernel/model/sync.go b/kernel/model/sync.go
index 800b826d47..1c96b11cd7 100644
--- a/kernel/model/sync.go
+++ b/kernel/model/sync.go
@@ -196,11 +196,11 @@ func SyncData(boot, exit, byHand bool) {
syncSameCount = 5
}
if !byHand {
- after := time.Minute * time.Duration(int(math.Pow(2, float64(syncSameCount))))
- if fixSyncInterval.Minutes() > after.Minutes() {
- after = time.Minute * 8
+ delay := time.Minute * time.Duration(int(math.Pow(2, float64(syncSameCount))))
+ if fixSyncInterval.Minutes() > delay.Minutes() {
+ delay = time.Minute * 8
}
- planSyncAfter(after)
+ planSyncAfter(delay)
}
Conf.Sync.Stat = Conf.Language(133)
@@ -460,6 +460,7 @@ func incReindex(upserts, removes []string) {
if !strings.HasSuffix(removeFile, ".sy") {
continue
}
+
id := strings.TrimSuffix(filepath.Base(removeFile), ".sy")
block := treenode.GetBlockTree(id)
if nil != block {
diff --git a/kernel/server/serve.go b/kernel/server/serve.go
index 55f738cf2e..2236ac8d1f 100644
--- a/kernel/server/serve.go
+++ b/kernel/server/serve.go
@@ -208,7 +208,7 @@ func serveAssets(ginServer *gin.Engine) {
dir := context.Param("dir")
name := context.Param("name")
relativePath := path.Join(dir, "assets", name)
- p := filepath.Join(util.WorkspaceDir, "history", relativePath)
+ p := filepath.Join(util.HistoryDir, relativePath)
http.ServeFile(context.Writer, context.Request, p)
return
})
diff --git a/kernel/util/working.go b/kernel/util/working.go
index 3c91a6ef31..af9aa1c2b5 100644
--- a/kernel/util/working.go
+++ b/kernel/util/working.go
@@ -140,7 +140,7 @@ func SetBooted() {
}
func GetHistoryDirNow(now, suffix string) (ret string, err error) {
- ret = filepath.Join(WorkspaceDir, "history", now+"-"+suffix)
+ ret = filepath.Join(HistoryDir, now+"-"+suffix)
if err = os.MkdirAll(ret, 0755); nil != err {
LogErrorf("make history dir failed: %s", err)
return
@@ -149,7 +149,7 @@ func GetHistoryDirNow(now, suffix string) (ret string, err error) {
}
func GetHistoryDir(suffix string) (ret string, err error) {
- ret = filepath.Join(WorkspaceDir, "history", time.Now().Format("2006-01-02-150405")+"-"+suffix)
+ ret = filepath.Join(HistoryDir, time.Now().Format("2006-01-02-150405")+"-"+suffix)
if err = os.MkdirAll(ret, 0755); nil != err {
LogErrorf("make history dir failed: %s", err)
return
@@ -165,6 +165,7 @@ var (
ConfDir string // 配置目录路径
DataDir string // 数据目录路径
RepoDir string // 仓库目录路径
+ HistoryDir string // 数据历史目录路径
TempDir string // 临时目录路径
LogPath string // 配置目录下的日志文件 siyuan.log 路径
DBName = "siyuan.db" // SQLite 数据库文件名
@@ -253,6 +254,7 @@ func initWorkspaceDir(workspaceArg string) {
ConfDir = filepath.Join(WorkspaceDir, "conf")
DataDir = filepath.Join(WorkspaceDir, "data")
RepoDir = filepath.Join(WorkspaceDir, "repo")
+ HistoryDir = filepath.Join(WorkspaceDir, "history")
TempDir = filepath.Join(WorkspaceDir, "temp")
osTmpDir := filepath.Join(TempDir, "os")
os.RemoveAll(osTmpDir)
diff --git a/kernel/util/working_mobile.go b/kernel/util/working_mobile.go
index dfdc649444..318908cb4e 100644
--- a/kernel/util/working_mobile.go
+++ b/kernel/util/working_mobile.go
@@ -37,6 +37,7 @@ func BootMobile(container, appDir, workspaceDir, nativeLibDir, privateDataDir, l
WorkspaceDir = workspaceDir
ConfDir = filepath.Join(workspaceDir, "conf")
DataDir = filepath.Join(workspaceDir, "data")
+ HistoryDir = filepath.Join(workspaceDir, "history")
RepoDir = filepath.Join(WorkspaceDir, "repo")
TempDir = filepath.Join(workspaceDir, "temp")
osTmpDir := filepath.Join(TempDir, "os")