Skip to content

Commit

Permalink
🎨 Improve boot sync
Browse files Browse the repository at this point in the history
  • Loading branch information
88250 committed Dec 23, 2024
1 parent 98180f2 commit 03c2611
Showing 1 changed file with 20 additions and 19 deletions.
39 changes: 20 additions & 19 deletions kernel/model/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -1288,14 +1288,13 @@ func bootSyncRepo() (err error) {

isBootSyncing.Store(true)

start := time.Now()

waitGroup := sync.WaitGroup{}
var errs []error
waitGroup.Add(1)
go func() {
defer waitGroup.Done()

start := time.Now()
_, _, indexErr := indexRepoBeforeCloudSync(repo)
if indexErr != nil {
errs = append(errs, indexErr)
Expand All @@ -1311,13 +1310,16 @@ func bootSyncRepo() (err error) {
isBootSyncing.Store(false)
return
}

logging.LogInfof("boot index repo elapsed [%.2fs]", time.Since(start).Seconds())
}()

var fetchedFiles []*entity.File
waitGroup.Add(1)
go func() {
defer waitGroup.Done()

start := time.Now()
syncContext := map[string]interface{}{eventbus.CtxPushMsg: eventbus.CtxPushMsgToStatusBar}
cloudLatest, getErr := repo.GetCloudLatest(syncContext)
if nil != getErr {
Expand All @@ -1342,29 +1344,14 @@ func bootSyncRepo() (err error) {
isBootSyncing.Store(false)
return
}

logging.LogInfof("boot get sync cloud files elapsed [%.2fs]", time.Since(start).Seconds())
}()
waitGroup.Wait()
if 0 < len(errs) {
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 {
autoSyncErrCount++
planSyncAfter(fixSyncInterval)
Expand All @@ -1387,6 +1374,20 @@ func bootSyncRepo() (err error) {
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) {
go func() {
_, syncErr := syncRepo(false, false)
Expand Down

0 comments on commit 03c2611

Please sign in to comment.