mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-31 22:08:48 +01:00
⚡ Improve data sync performance for booting https://github.com/siyuan-note/siyuan/issues/13216
This commit is contained in:
parent
0e357f7311
commit
eba4dfa0da
3 changed files with 60 additions and 31 deletions
|
|
@ -1285,34 +1285,63 @@ func bootSyncRepo() (err error) {
|
|||
isBootSyncing.Store(true)
|
||||
|
||||
start := time.Now()
|
||||
_, _, err = indexRepoBeforeCloudSync(repo)
|
||||
if err != nil {
|
||||
autoSyncErrCount++
|
||||
planSyncAfter(fixSyncInterval)
|
||||
|
||||
msg := fmt.Sprintf(Conf.Language(80), formatRepoErrorMsg(err))
|
||||
Conf.Sync.Stat = msg
|
||||
Conf.Save()
|
||||
util.PushStatusBar(msg)
|
||||
util.PushErrMsg(msg, 0)
|
||||
BootSyncSucc = 1
|
||||
isBootSyncing.Store(false)
|
||||
return
|
||||
}
|
||||
waitGroup := sync.WaitGroup{}
|
||||
var errs []error
|
||||
waitGroup.Add(1)
|
||||
go func() {
|
||||
defer waitGroup.Done()
|
||||
|
||||
syncContext := map[string]interface{}{eventbus.CtxPushMsg: eventbus.CtxPushMsgToStatusBar}
|
||||
fetchedFiles, err := repo.GetSyncCloudFiles(syncContext)
|
||||
if errors.Is(err, dejavu.ErrRepoFatal) {
|
||||
autoSyncErrCount++
|
||||
planSyncAfter(fixSyncInterval)
|
||||
_, _, indexErr := indexRepoBeforeCloudSync(repo)
|
||||
if indexErr != nil {
|
||||
errs = append(errs, indexErr)
|
||||
autoSyncErrCount++
|
||||
planSyncAfter(fixSyncInterval)
|
||||
|
||||
msg := fmt.Sprintf(Conf.Language(80), formatRepoErrorMsg(err))
|
||||
Conf.Sync.Stat = msg
|
||||
Conf.Save()
|
||||
util.PushStatusBar(msg)
|
||||
util.PushErrMsg(msg, 0)
|
||||
BootSyncSucc = 1
|
||||
isBootSyncing.Store(false)
|
||||
msg := fmt.Sprintf(Conf.Language(80), formatRepoErrorMsg(indexErr))
|
||||
Conf.Sync.Stat = msg
|
||||
Conf.Save()
|
||||
util.PushStatusBar(msg)
|
||||
util.PushErrMsg(msg, 0)
|
||||
BootSyncSucc = 1
|
||||
isBootSyncing.Store(false)
|
||||
return
|
||||
}
|
||||
}()
|
||||
|
||||
var fetchedFiles []*entity.File
|
||||
waitGroup.Add(1)
|
||||
go func() {
|
||||
defer waitGroup.Done()
|
||||
|
||||
syncContext := map[string]interface{}{eventbus.CtxPushMsg: eventbus.CtxPushMsgToStatusBar}
|
||||
cloudLatest, getErr := repo.GetCloudLatest(syncContext)
|
||||
if nil != getErr {
|
||||
errs = append(errs, getErr)
|
||||
if !errors.Is(getErr, cloud.ErrCloudObjectNotFound) {
|
||||
logging.LogErrorf("download cloud latest failed: %s", getErr)
|
||||
return
|
||||
}
|
||||
}
|
||||
fetchedFiles, getErr = repo.GetSyncCloudFiles(cloudLatest, syncContext)
|
||||
if errors.Is(getErr, dejavu.ErrRepoFatal) {
|
||||
errs = append(errs, getErr)
|
||||
autoSyncErrCount++
|
||||
planSyncAfter(fixSyncInterval)
|
||||
|
||||
msg := fmt.Sprintf(Conf.Language(80), formatRepoErrorMsg(getErr))
|
||||
Conf.Sync.Stat = msg
|
||||
Conf.Save()
|
||||
util.PushStatusBar(msg)
|
||||
util.PushErrMsg(msg, 0)
|
||||
BootSyncSucc = 1
|
||||
isBootSyncing.Store(false)
|
||||
return
|
||||
}
|
||||
}()
|
||||
waitGroup.Wait()
|
||||
if 0 < len(errs) {
|
||||
err = errs[0]
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue