mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-17 23:20:13 +01:00
🎨 Improve cloud sync
This commit is contained in:
parent
acddd46012
commit
f63d551e2e
3 changed files with 44 additions and 17 deletions
|
|
@ -41,7 +41,7 @@ require (
|
||||||
github.com/qiniu/go-sdk/v7 v7.13.0
|
github.com/qiniu/go-sdk/v7 v7.13.0
|
||||||
github.com/radovskyb/watcher v1.0.7
|
github.com/radovskyb/watcher v1.0.7
|
||||||
github.com/sabhiram/go-gitignore v0.0.0-20210923224102-525f6e181f06
|
github.com/sabhiram/go-gitignore v0.0.0-20210923224102-525f6e181f06
|
||||||
github.com/siyuan-note/dejavu v0.0.0-20220706152612-01484c9d21c7
|
github.com/siyuan-note/dejavu v0.0.0-20220707133820-6e8292d6d3e5
|
||||||
github.com/siyuan-note/encryption v0.0.0-20220612074546-f1dd94fe8676
|
github.com/siyuan-note/encryption v0.0.0-20220612074546-f1dd94fe8676
|
||||||
github.com/siyuan-note/eventbus v0.0.0-20220624162334-ca7c06dc771f
|
github.com/siyuan-note/eventbus v0.0.0-20220624162334-ca7c06dc771f
|
||||||
github.com/siyuan-note/filelock v0.0.0-20220704090116-54dfb035283f
|
github.com/siyuan-note/filelock v0.0.0-20220704090116-54dfb035283f
|
||||||
|
|
|
||||||
|
|
@ -426,6 +426,8 @@ github.com/shurcooL/vfsgen v0.0.0-20200824052919-0d455de96546/go.mod h1:TrYk7fJV
|
||||||
github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
|
github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
|
||||||
github.com/siyuan-note/dejavu v0.0.0-20220706152612-01484c9d21c7 h1:zmn9x7bGlXxt9KB7+3r2QVEcI1bAaanXG1t8BQwL4MI=
|
github.com/siyuan-note/dejavu v0.0.0-20220706152612-01484c9d21c7 h1:zmn9x7bGlXxt9KB7+3r2QVEcI1bAaanXG1t8BQwL4MI=
|
||||||
github.com/siyuan-note/dejavu v0.0.0-20220706152612-01484c9d21c7/go.mod h1:ral+X0pNW6nSQVvIcxllUXSczCaY4UOCT2iGlO4YNg0=
|
github.com/siyuan-note/dejavu v0.0.0-20220706152612-01484c9d21c7/go.mod h1:ral+X0pNW6nSQVvIcxllUXSczCaY4UOCT2iGlO4YNg0=
|
||||||
|
github.com/siyuan-note/dejavu v0.0.0-20220707133820-6e8292d6d3e5 h1:rGr2cYzD+DCc3flnvsDamaHag66xWVZ7OjHXDACf3CI=
|
||||||
|
github.com/siyuan-note/dejavu v0.0.0-20220707133820-6e8292d6d3e5/go.mod h1:ral+X0pNW6nSQVvIcxllUXSczCaY4UOCT2iGlO4YNg0=
|
||||||
github.com/siyuan-note/encryption v0.0.0-20220612074546-f1dd94fe8676 h1:QB9TjJQFhXhZ6dAtPpY02DlzHAQm1C+WqZq6OadG8mI=
|
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/encryption v0.0.0-20220612074546-f1dd94fe8676/go.mod h1:H8fyqqAbp9XreANjeSbc72zEdFfKTXYN34tc1TjZwtw=
|
||||||
github.com/siyuan-note/eventbus v0.0.0-20220624162334-ca7c06dc771f h1:JMobMNZ7AqaKKyEK+WeWFhix/2TDQXgPZDajU00IybU=
|
github.com/siyuan-note/eventbus v0.0.0-20220624162334-ca7c06dc771f h1:JMobMNZ7AqaKKyEK+WeWFhix/2TDQXgPZDajU00IybU=
|
||||||
|
|
|
||||||
|
|
@ -442,10 +442,7 @@ func syncRepo(boot, exit, byHand bool) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
syncContext := map[string]interface{}{dejavu.CtxPushMsg: dejavu.CtxPushMsgToStatusBar}
|
syncContext := map[string]interface{}{dejavu.CtxPushMsg: dejavu.CtxPushMsgToStatusBar}
|
||||||
|
_, mergeResult, trafficStat, err := repo.Sync(cloudInfo, syncContext)
|
||||||
_, mergeUpserts, mergeRemoves, _,
|
|
||||||
uploadFileCount, downloadFileCount, uploadChunkCount, downloadChunkCount,
|
|
||||||
uploadBytes, downloadBytes, err := repo.Sync(cloudInfo, syncContext)
|
|
||||||
|
|
||||||
elapsed := time.Since(start)
|
elapsed := time.Since(start)
|
||||||
if nil != err {
|
if nil != err {
|
||||||
|
|
@ -468,10 +465,10 @@ func syncRepo(boot, exit, byHand bool) {
|
||||||
}
|
}
|
||||||
util.PushStatusBar(fmt.Sprintf(Conf.Language(149), elapsed.Seconds()))
|
util.PushStatusBar(fmt.Sprintf(Conf.Language(149), elapsed.Seconds()))
|
||||||
Conf.Sync.Synced = util.CurrentTimeMillis()
|
Conf.Sync.Synced = util.CurrentTimeMillis()
|
||||||
msg := fmt.Sprintf(Conf.Language(150), uploadFileCount, downloadFileCount, uploadChunkCount, downloadChunkCount, byteCountSI(uploadBytes), byteCountSI(downloadBytes))
|
msg := fmt.Sprintf(Conf.Language(150), trafficStat.UploadFileCount, trafficStat.DownloadFileCount, trafficStat.UploadChunkCount, trafficStat.DownloadChunkCount, byteCountSI(trafficStat.UploadBytes), byteCountSI(trafficStat.DownloadBytes))
|
||||||
Conf.Sync.Stat = msg
|
Conf.Sync.Stat = msg
|
||||||
|
|
||||||
if 1 > len(mergeUpserts) && 1 > len(mergeRemoves) { // 没有数据变更
|
if 1 > len(mergeResult.Upserts) && 1 > len(mergeResult.Removes) { // 没有数据变更
|
||||||
syncSameCount++
|
syncSameCount++
|
||||||
if 10 < syncSameCount {
|
if 10 < syncSameCount {
|
||||||
syncSameCount = 5
|
syncSameCount = 5
|
||||||
|
|
@ -489,10 +486,10 @@ func syncRepo(boot, exit, byHand bool) {
|
||||||
|
|
||||||
// 有数据变更,需要重建索引
|
// 有数据变更,需要重建索引
|
||||||
var upserts, removes []string
|
var upserts, removes []string
|
||||||
for _, file := range mergeUpserts {
|
for _, file := range mergeResult.Upserts {
|
||||||
upserts = append(upserts, file.Path)
|
upserts = append(upserts, file.Path)
|
||||||
}
|
}
|
||||||
for _, file := range mergeRemoves {
|
for _, file := range mergeResult.Removes {
|
||||||
removes = append(removes, file.Path)
|
removes = append(removes, file.Path)
|
||||||
}
|
}
|
||||||
incReindex(upserts, removes)
|
incReindex(upserts, removes)
|
||||||
|
|
@ -583,26 +580,54 @@ func subscribeEvents() {
|
||||||
contextPushMsg(context, msg)
|
contextPushMsg(context, msg)
|
||||||
})
|
})
|
||||||
|
|
||||||
eventbus.Subscribe(dejavu.EvtBeforeDownloadCloudIndex, func(context map[string]interface{}) {
|
eventbus.Subscribe(dejavu.EvtCloudBeforeDownloadIndex, func(context map[string]interface{}, id string) {
|
||||||
msg := "Downloading data repository latest..."
|
msg := "Downloading data repository index [" + id + "]"
|
||||||
util.SetBootDetails(msg)
|
util.SetBootDetails(msg)
|
||||||
contextPushMsg(context, msg)
|
contextPushMsg(context, msg)
|
||||||
})
|
})
|
||||||
|
|
||||||
eventbus.Subscribe(dejavu.EvtBeforeDownloadCloudFile, func(context map[string]interface{}, id string) {
|
eventbus.Subscribe(dejavu.EvtCloudBeforeDownloadFile, func(context map[string]interface{}, id string) {
|
||||||
msg := "Downloading data repository object [" + id + "]"
|
msg := "Downloading data repository file [" + id + "]"
|
||||||
|
util.SetBootDetails(msg)
|
||||||
|
contextPushMsg(context, msg)
|
||||||
|
//util.LogInfof("%s", msg)
|
||||||
|
})
|
||||||
|
|
||||||
|
eventbus.Subscribe(dejavu.EvtCloudBeforeDownloadChunk, func(context map[string]interface{}, id string) {
|
||||||
|
msg := "Downloading data repository chunk [" + id + "]"
|
||||||
|
util.SetBootDetails(msg)
|
||||||
|
contextPushMsg(context, msg)
|
||||||
|
//util.LogInfof("%s", msg)
|
||||||
|
})
|
||||||
|
|
||||||
|
eventbus.Subscribe(dejavu.EvtCloudBeforeDownloadRef, func(context map[string]interface{}, ref string) {
|
||||||
|
msg := "Downloading data repository ref [" + ref + "]"
|
||||||
util.SetBootDetails(msg)
|
util.SetBootDetails(msg)
|
||||||
contextPushMsg(context, msg)
|
contextPushMsg(context, msg)
|
||||||
})
|
})
|
||||||
|
|
||||||
eventbus.Subscribe(dejavu.EvtBeforeDownloadCloudChunk, func(context map[string]interface{}, id string) {
|
eventbus.Subscribe(dejavu.EvtCloudBeforeUploadIndex, func(context map[string]interface{}, id string) {
|
||||||
msg := "Downloading data repository object [" + id + "]"
|
msg := "Uploading data repository index [" + id + "]"
|
||||||
util.SetBootDetails(msg)
|
util.SetBootDetails(msg)
|
||||||
contextPushMsg(context, msg)
|
contextPushMsg(context, msg)
|
||||||
})
|
})
|
||||||
|
|
||||||
eventbus.Subscribe(dejavu.EvtBeforeUploadObject, func(context map[string]interface{}, id string) {
|
eventbus.Subscribe(dejavu.EvtCloudBeforeUploadFile, func(context map[string]interface{}, id string) {
|
||||||
msg := "Uploading data repository object [" + id + "]"
|
msg := "Uploading data repository file [" + id + "]"
|
||||||
|
util.SetBootDetails(msg)
|
||||||
|
contextPushMsg(context, msg)
|
||||||
|
//util.LogInfof("%s", msg)
|
||||||
|
})
|
||||||
|
|
||||||
|
eventbus.Subscribe(dejavu.EvtCloudBeforeUploadChunk, func(context map[string]interface{}, id string) {
|
||||||
|
msg := "Uploading data repository chunk [" + id + "]"
|
||||||
|
util.SetBootDetails(msg)
|
||||||
|
contextPushMsg(context, msg)
|
||||||
|
//util.LogInfof("%s", msg)
|
||||||
|
})
|
||||||
|
|
||||||
|
eventbus.Subscribe(dejavu.EvtCloudBeforeUploadRef, func(context map[string]interface{}, ref string) {
|
||||||
|
msg := "Uploading data repository ref [" + ref + "]"
|
||||||
util.SetBootDetails(msg)
|
util.SetBootDetails(msg)
|
||||||
contextPushMsg(context, msg)
|
contextPushMsg(context, msg)
|
||||||
})
|
})
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue