mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-19 16:10:12 +01:00
🎨 Improve boot sync
This commit is contained in:
parent
98180f2c5e
commit
03c2611c0f
1 changed files with 20 additions and 19 deletions
|
|
@ -1288,14 +1288,13 @@ func bootSyncRepo() (err error) {
|
||||||
|
|
||||||
isBootSyncing.Store(true)
|
isBootSyncing.Store(true)
|
||||||
|
|
||||||
start := time.Now()
|
|
||||||
|
|
||||||
waitGroup := sync.WaitGroup{}
|
waitGroup := sync.WaitGroup{}
|
||||||
var errs []error
|
var errs []error
|
||||||
waitGroup.Add(1)
|
waitGroup.Add(1)
|
||||||
go func() {
|
go func() {
|
||||||
defer waitGroup.Done()
|
defer waitGroup.Done()
|
||||||
|
|
||||||
|
start := time.Now()
|
||||||
_, _, indexErr := indexRepoBeforeCloudSync(repo)
|
_, _, indexErr := indexRepoBeforeCloudSync(repo)
|
||||||
if indexErr != nil {
|
if indexErr != nil {
|
||||||
errs = append(errs, indexErr)
|
errs = append(errs, indexErr)
|
||||||
|
|
@ -1311,6 +1310,8 @@ func bootSyncRepo() (err error) {
|
||||||
isBootSyncing.Store(false)
|
isBootSyncing.Store(false)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logging.LogInfof("boot index repo elapsed [%.2fs]", time.Since(start).Seconds())
|
||||||
}()
|
}()
|
||||||
|
|
||||||
var fetchedFiles []*entity.File
|
var fetchedFiles []*entity.File
|
||||||
|
|
@ -1318,6 +1319,7 @@ func bootSyncRepo() (err error) {
|
||||||
go func() {
|
go func() {
|
||||||
defer waitGroup.Done()
|
defer waitGroup.Done()
|
||||||
|
|
||||||
|
start := time.Now()
|
||||||
syncContext := map[string]interface{}{eventbus.CtxPushMsg: eventbus.CtxPushMsgToStatusBar}
|
syncContext := map[string]interface{}{eventbus.CtxPushMsg: eventbus.CtxPushMsgToStatusBar}
|
||||||
cloudLatest, getErr := repo.GetCloudLatest(syncContext)
|
cloudLatest, getErr := repo.GetCloudLatest(syncContext)
|
||||||
if nil != getErr {
|
if nil != getErr {
|
||||||
|
|
@ -1342,29 +1344,14 @@ func bootSyncRepo() (err error) {
|
||||||
isBootSyncing.Store(false)
|
isBootSyncing.Store(false)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logging.LogInfof("boot get sync cloud files elapsed [%.2fs]", time.Since(start).Seconds())
|
||||||
}()
|
}()
|
||||||
waitGroup.Wait()
|
waitGroup.Wait()
|
||||||
if 0 < len(errs) {
|
if 0 < len(errs) {
|
||||||
err = errs[0]
|
err = errs[0]
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
syncingFiles = sync.Map{}
|
|
||||||
syncingStorages.Store(false)
|
|
||||||
for _, fetchedFile := range fetchedFiles {
|
|
||||||
name := path.Base(fetchedFile.Path)
|
|
||||||
if strings.HasSuffix(name, ".sy") {
|
|
||||||
id := name[:len(name)-3]
|
|
||||||
syncingFiles.Store(id, true)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if strings.HasPrefix(fetchedFile.Path, "/storage/") {
|
|
||||||
syncingStorages.Store(true)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
elapsed := time.Since(start)
|
|
||||||
logging.LogInfof("boot get sync cloud files elapsed [%.2fs]", elapsed.Seconds())
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
autoSyncErrCount++
|
autoSyncErrCount++
|
||||||
planSyncAfter(fixSyncInterval)
|
planSyncAfter(fixSyncInterval)
|
||||||
|
|
@ -1387,6 +1374,20 @@ func bootSyncRepo() (err error) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
syncingFiles = sync.Map{}
|
||||||
|
syncingStorages.Store(false)
|
||||||
|
for _, fetchedFile := range fetchedFiles {
|
||||||
|
name := path.Base(fetchedFile.Path)
|
||||||
|
if strings.HasSuffix(name, ".sy") {
|
||||||
|
id := name[:len(name)-3]
|
||||||
|
syncingFiles.Store(id, true)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if strings.HasPrefix(fetchedFile.Path, "/storage/") {
|
||||||
|
syncingStorages.Store(true)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if 0 < len(fetchedFiles) {
|
if 0 < len(fetchedFiles) {
|
||||||
go func() {
|
go func() {
|
||||||
_, syncErr := syncRepo(false, false)
|
_, syncErr := syncRepo(false, false)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue