🎨 云端同步时自动创建数据快照

This commit is contained in:
Liang Ding 2022-06-16 13:10:23 +08:00
parent 1679df6209
commit 3538a01d3b
No known key found for this signature in database
GPG key ID: 136F30F901A2231D
3 changed files with 18 additions and 12 deletions

View file

@ -20,6 +20,7 @@ import (
"crypto/rand"
"encoding/hex"
"errors"
"fmt"
"os"
"time"
@ -214,13 +215,23 @@ func indexRepoBeforeCloudSync() {
}
start := time.Now()
_, err = repo.Index("[Auto] Cloud sync", nil, nil)
latest, err := repo.Latest()
index, err := repo.Index("[Auto] Cloud sync", nil, nil)
if nil != err {
util.LogErrorf("index repo before cloud sync failed: %s", err)
return
}
elapsed := time.Since(start).Milliseconds()
if 7000 < elapsed {
util.LogWarnf("index repo before cloud sync elapsed [%dms]", elapsed)
elapsed := time.Since(start)
if nil != latest && latest.ID != index.ID {
// 对新创建的快照需要更新备注,加入耗时统计
index.Memo = fmt.Sprintf("[Auto] Cloud sync, completed in [%.2fs]", elapsed.Seconds())
err = repo.PutIndex(index)
if nil != err {
util.LogErrorf("put index into repo before cloud sync failed: %s", err)
return
}
}
if 7000 < elapsed.Milliseconds() {
util.LogWarnf("index repo before cloud sync elapsed [%dms]", elapsed.Milliseconds())
}
}