🎨 Error notification pops up only once after auto sync fails https://github.com/siyuan-note/siyuan/issues/8096

This commit is contained in:
Liang Ding 2023-04-24 15:29:34 +08:00
parent 0fc3f045e0
commit 2a8378c327
No known key found for this signature in database
GPG key ID: 136F30F901A2231D
4 changed files with 30 additions and 25 deletions

View file

@ -1046,7 +1046,7 @@
"121": "該文檔中不存在網絡圖片", "121": "該文檔中不存在網絡圖片",
"123": "新增/選擇雲端同步目錄後才能啟用同步功能", "123": "新增/選擇雲端同步目錄後才能啟用同步功能",
"124": "請在 [設置 - 啟用雲端同步] 中開啟雲端同步", "124": "請在 [設置 - 啟用雲端同步] 中開啟雲端同步",
"125": "自動同步下載失敗次數過多,請嘗試手動觸發同步,如果還有問題請<a href=\"https://ld246.com/article/1649901726096\" target=\"_blank\">回饋</a>", "125": "自動同步失敗次數過多,請嘗試手動觸發同步,如果還有問題請<a href=\"https://ld246.com/article/1649901726096\" target=\"_blank\">回饋</a>",
"126": "書籤不能為空", "126": "書籤不能為空",
"127": "訂閱距過期還剩 [%d] 天,過期後雲端數據會被徹底刪除。續訂請訪問<a target='_blank' href='https://ld246.com/subscribe/siyuan'>這裡</a>", "127": "訂閱距過期還剩 [%d] 天,過期後雲端數據會被徹底刪除。續訂請訪問<a target='_blank' href='https://ld246.com/subscribe/siyuan'>這裡</a>",
"128": "訂閱已經過期,過期後雲端數據會被徹底刪除,訂閱過期兩天后不再彈出該提醒,續訂請訪問<a target='_blank' href='https://ld246.com/subscribe/siyuan'>這裡</a>", "128": "訂閱已經過期,過期後雲端數據會被徹底刪除,訂閱過期兩天后不再彈出該提醒,續訂請訪問<a target='_blank' href='https://ld246.com/subscribe/siyuan'>這裡</a>",

View file

@ -1048,7 +1048,7 @@
"122": "该功能需在思源桌面端进行配置。如果你已经配置,请在顶部账号设置中进行刷新", "122": "该功能需在思源桌面端进行配置。如果你已经配置,请在顶部账号设置中进行刷新",
"123": "添加/选择云端同步目录后才能启用同步功能", "123": "添加/选择云端同步目录后才能启用同步功能",
"124": "请在 [设置 - 启用云端同步] 中开启云端同步", "124": "请在 [设置 - 启用云端同步] 中开启云端同步",
"125": "自动同步下载失败次数过多,请尝试手动触发同步,如果还有问题请<a href=\"https://ld246.com/article/1649901726096\" target=\"_blank\">反馈</a>", "125": "自动同步失败次数过多,请尝试手动触发同步,如果还有问题请<a href=\"https://ld246.com/article/1649901726096\" target=\"_blank\">反馈</a>",
"126": "书签不能为空", "126": "书签不能为空",
"127": "订阅距过期还剩 [%d] 天,过期后云端数据会被彻底删除。续订请访问<a target='_blank' href='https://ld246.com/subscribe/siyuan'>这里</a>", "127": "订阅距过期还剩 [%d] 天,过期后云端数据会被彻底删除。续订请访问<a target='_blank' href='https://ld246.com/subscribe/siyuan'>这里</a>",
"128": "订阅已经过期,过期后云端数据会被彻底删除,订阅过期两天后不再弹出该提醒,续订请访问<a target='_blank' href='https://ld246.com/subscribe/siyuan'>这里</a>", "128": "订阅已经过期,过期后云端数据会被彻底删除,订阅过期两天后不再弹出该提醒,续订请访问<a target='_blank' href='https://ld246.com/subscribe/siyuan'>这里</a>",

View file

@ -902,7 +902,7 @@ func syncRepoDownload() (err error) {
Conf.Sync.Synced = util.CurrentTimeMillis() Conf.Sync.Synced = util.CurrentTimeMillis()
msg := fmt.Sprintf(Conf.Language(150), trafficStat.UploadFileCount, trafficStat.DownloadFileCount, trafficStat.UploadChunkCount, trafficStat.DownloadChunkCount, humanize.Bytes(uint64(trafficStat.UploadBytes)), humanize.Bytes(uint64(trafficStat.DownloadBytes))) msg := fmt.Sprintf(Conf.Language(150), trafficStat.UploadFileCount, trafficStat.DownloadFileCount, trafficStat.UploadChunkCount, trafficStat.DownloadChunkCount, humanize.Bytes(uint64(trafficStat.UploadBytes)), humanize.Bytes(uint64(trafficStat.DownloadBytes)))
Conf.Sync.Stat = msg Conf.Sync.Stat = msg
syncDownloadErrCount = 0 autoSyncErrCount = 0
logging.LogInfof("synced data repo download [provider=%d, ufc=%d, dfc=%d, ucc=%d, dcc=%d, ub=%s, db=%s] in [%.2fs]", logging.LogInfof("synced data repo download [provider=%d, ufc=%d, dfc=%d, ucc=%d, dcc=%d, ub=%s, db=%s] in [%.2fs]",
Conf.Sync.Provider, trafficStat.UploadFileCount, trafficStat.DownloadFileCount, trafficStat.UploadChunkCount, trafficStat.DownloadChunkCount, humanize.Bytes(uint64(trafficStat.UploadBytes)), humanize.Bytes(uint64(trafficStat.DownloadBytes)), elapsed.Seconds()) Conf.Sync.Provider, trafficStat.UploadFileCount, trafficStat.DownloadFileCount, trafficStat.UploadChunkCount, trafficStat.DownloadChunkCount, humanize.Bytes(uint64(trafficStat.UploadBytes)), humanize.Bytes(uint64(trafficStat.DownloadBytes)), elapsed.Seconds())
@ -969,6 +969,7 @@ func syncRepoUpload() (err error) {
Conf.Sync.Synced = util.CurrentTimeMillis() Conf.Sync.Synced = util.CurrentTimeMillis()
msg := fmt.Sprintf(Conf.Language(150), trafficStat.UploadFileCount, trafficStat.DownloadFileCount, trafficStat.UploadChunkCount, trafficStat.DownloadChunkCount, humanize.Bytes(uint64(trafficStat.UploadBytes)), humanize.Bytes(uint64(trafficStat.DownloadBytes))) msg := fmt.Sprintf(Conf.Language(150), trafficStat.UploadFileCount, trafficStat.DownloadFileCount, trafficStat.UploadChunkCount, trafficStat.DownloadChunkCount, humanize.Bytes(uint64(trafficStat.UploadBytes)), humanize.Bytes(uint64(trafficStat.DownloadBytes)))
Conf.Sync.Stat = msg Conf.Sync.Stat = msg
autoSyncErrCount = 0
logging.LogInfof("synced data repo upload [provider=%d, ufc=%d, dfc=%d, ucc=%d, dcc=%d, ub=%s, db=%s] in [%.2fs]", logging.LogInfof("synced data repo upload [provider=%d, ufc=%d, dfc=%d, ucc=%d, dcc=%d, ub=%s, db=%s] in [%.2fs]",
Conf.Sync.Provider, trafficStat.UploadFileCount, trafficStat.DownloadFileCount, trafficStat.UploadChunkCount, trafficStat.DownloadChunkCount, humanize.Bytes(uint64(trafficStat.UploadBytes)), humanize.Bytes(uint64(trafficStat.DownloadBytes)), elapsed.Seconds()) Conf.Sync.Provider, trafficStat.UploadFileCount, trafficStat.DownloadFileCount, trafficStat.UploadChunkCount, trafficStat.DownloadChunkCount, humanize.Bytes(uint64(trafficStat.UploadBytes)), humanize.Bytes(uint64(trafficStat.DownloadBytes)), elapsed.Seconds())
return return
@ -976,7 +977,7 @@ func syncRepoUpload() (err error) {
func bootSyncRepo() (err error) { func bootSyncRepo() (err error) {
if 1 > len(Conf.Repo.Key) { if 1 > len(Conf.Repo.Key) {
syncDownloadErrCount++ autoSyncErrCount++
planSyncAfter(fixSyncInterval) planSyncAfter(fixSyncInterval)
msg := Conf.Language(26) msg := Conf.Language(26)
@ -988,7 +989,7 @@ func bootSyncRepo() (err error) {
repo, err := newRepository() repo, err := newRepository()
if nil != err { if nil != err {
syncDownloadErrCount++ autoSyncErrCount++
planSyncAfter(fixSyncInterval) planSyncAfter(fixSyncInterval)
msg := fmt.Sprintf("sync repo failed: %s", err) msg := fmt.Sprintf("sync repo failed: %s", err)
@ -1001,7 +1002,7 @@ func bootSyncRepo() (err error) {
start := time.Now() start := time.Now()
err = indexRepoBeforeCloudSync(repo) err = indexRepoBeforeCloudSync(repo)
if nil != err { if nil != err {
syncDownloadErrCount++ autoSyncErrCount++
planSyncAfter(fixSyncInterval) planSyncAfter(fixSyncInterval)
return return
} }
@ -1032,7 +1033,7 @@ func bootSyncRepo() (err error) {
elapsed := time.Since(start) elapsed := time.Since(start)
logging.LogInfof("boot get sync cloud files elapsed [%.2fs]", elapsed.Seconds()) logging.LogInfof("boot get sync cloud files elapsed [%.2fs]", elapsed.Seconds())
if nil != err { if nil != err {
syncDownloadErrCount++ autoSyncErrCount++
planSyncAfter(fixSyncInterval) planSyncAfter(fixSyncInterval)
logging.LogErrorf("sync data repo failed: %s", err) logging.LogErrorf("sync data repo failed: %s", err)
@ -1067,7 +1068,7 @@ func bootSyncRepo() (err error) {
func syncRepo(exit, byHand bool) (err error) { func syncRepo(exit, byHand bool) (err error) {
if 1 > len(Conf.Repo.Key) { if 1 > len(Conf.Repo.Key) {
syncDownloadErrCount++ autoSyncErrCount++
planSyncAfter(fixSyncInterval) planSyncAfter(fixSyncInterval)
msg := Conf.Language(26) msg := Conf.Language(26)
@ -1079,7 +1080,7 @@ func syncRepo(exit, byHand bool) (err error) {
repo, err := newRepository() repo, err := newRepository()
if nil != err { if nil != err {
syncDownloadErrCount++ autoSyncErrCount++
planSyncAfter(fixSyncInterval) planSyncAfter(fixSyncInterval)
msg := fmt.Sprintf("sync repo failed: %s", err) msg := fmt.Sprintf("sync repo failed: %s", err)
@ -1092,7 +1093,7 @@ func syncRepo(exit, byHand bool) (err error) {
start := time.Now() start := time.Now()
err = indexRepoBeforeCloudSync(repo) err = indexRepoBeforeCloudSync(repo)
if nil != err { if nil != err {
syncDownloadErrCount++ autoSyncErrCount++
planSyncAfter(fixSyncInterval) planSyncAfter(fixSyncInterval)
return return
} }
@ -1107,7 +1108,7 @@ func syncRepo(exit, byHand bool) (err error) {
} }
elapsed := time.Since(start) elapsed := time.Since(start)
if nil != err { if nil != err {
syncDownloadErrCount++ autoSyncErrCount++
planSyncAfter(fixSyncInterval) planSyncAfter(fixSyncInterval)
logging.LogErrorf("sync data repo failed: %s", err) logging.LogErrorf("sync data repo failed: %s", err)
@ -1120,7 +1121,9 @@ func syncRepo(exit, byHand bool) (err error) {
} }
Conf.Sync.Stat = msg Conf.Sync.Stat = msg
util.PushStatusBar(msg) util.PushStatusBar(msg)
util.PushErrMsg(msg, 0) if 1 > autoSyncErrCount || byHand {
util.PushErrMsg(msg, 0)
}
if exit { if exit {
ExitSyncSucc = 1 ExitSyncSucc = 1
} }
@ -1131,7 +1134,7 @@ func syncRepo(exit, byHand bool) (err error) {
Conf.Sync.Synced = util.CurrentTimeMillis() Conf.Sync.Synced = util.CurrentTimeMillis()
msg := fmt.Sprintf(Conf.Language(150), trafficStat.UploadFileCount, trafficStat.DownloadFileCount, trafficStat.UploadChunkCount, trafficStat.DownloadChunkCount, humanize.Bytes(uint64(trafficStat.UploadBytes)), humanize.Bytes(uint64(trafficStat.DownloadBytes))) msg := fmt.Sprintf(Conf.Language(150), trafficStat.UploadFileCount, trafficStat.DownloadFileCount, trafficStat.UploadChunkCount, trafficStat.DownloadChunkCount, humanize.Bytes(uint64(trafficStat.UploadBytes)), humanize.Bytes(uint64(trafficStat.DownloadBytes)))
Conf.Sync.Stat = msg Conf.Sync.Stat = msg
syncDownloadErrCount = 0 autoSyncErrCount = 0
logging.LogInfof("synced data repo [provider=%d, ufc=%d, dfc=%d, ucc=%d, dcc=%d, ub=%s, db=%s] in [%.2fs]", logging.LogInfof("synced data repo [provider=%d, ufc=%d, dfc=%d, ucc=%d, dcc=%d, ub=%s, db=%s] in [%.2fs]",
Conf.Sync.Provider, trafficStat.UploadFileCount, trafficStat.DownloadFileCount, trafficStat.UploadChunkCount, trafficStat.DownloadChunkCount, humanize.Bytes(uint64(trafficStat.UploadBytes)), humanize.Bytes(uint64(trafficStat.DownloadBytes)), elapsed.Seconds()) Conf.Sync.Provider, trafficStat.UploadFileCount, trafficStat.DownloadFileCount, trafficStat.UploadChunkCount, trafficStat.DownloadChunkCount, humanize.Bytes(uint64(trafficStat.UploadBytes)), humanize.Bytes(uint64(trafficStat.DownloadBytes)), elapsed.Seconds())

View file

@ -46,7 +46,7 @@ func SyncDataDownload() {
} }
util.BroadcastByType("main", "syncing", 0, Conf.Language(81), nil) util.BroadcastByType("main", "syncing", 0, Conf.Language(81), nil)
if !isProviderOnline() { // 这个操作比较耗时,所以要先推送 syncing 事件后再判断网络,这样才能给用户更即时的反馈 if !isProviderOnline(true) { // 这个操作比较耗时,所以要先推送 syncing 事件后再判断网络,这样才能给用户更即时的反馈
util.BroadcastByType("main", "syncing", 2, Conf.Language(28), nil) util.BroadcastByType("main", "syncing", 2, Conf.Language(28), nil)
return return
} }
@ -82,7 +82,7 @@ func SyncDataUpload() {
} }
util.BroadcastByType("main", "syncing", 0, Conf.Language(81), nil) util.BroadcastByType("main", "syncing", 0, Conf.Language(81), nil)
if !isProviderOnline() { // 这个操作比较耗时,所以要先推送 syncing 事件后再判断网络,这样才能给用户更即时的反馈 if !isProviderOnline(true) { // 这个操作比较耗时,所以要先推送 syncing 事件后再判断网络,这样才能给用户更即时的反馈
util.BroadcastByType("main", "syncing", 2, Conf.Language(28), nil) util.BroadcastByType("main", "syncing", 2, Conf.Language(28), nil)
return return
} }
@ -112,10 +112,10 @@ func SyncDataUpload() {
} }
var ( var (
syncSameCount = 0 syncSameCount = 0
syncDownloadErrCount = 0 autoSyncErrCount = 0
fixSyncInterval = 5 * time.Minute fixSyncInterval = 5 * time.Minute
syncPlanTime = time.Now().Add(fixSyncInterval) syncPlanTime = time.Now().Add(fixSyncInterval)
BootSyncSucc = -1 // -1未执行0执行成功1执行失败 BootSyncSucc = -1 // -1未执行0执行成功1执行失败
ExitSyncSucc = -1 ExitSyncSucc = -1
@ -136,7 +136,7 @@ func BootSyncData() {
return return
} }
if !isProviderOnline() { if !isProviderOnline(false) {
BootSyncSucc = 1 BootSyncSucc = 1
util.PushErrMsg(Conf.Language(28), 7000) util.PushErrMsg(Conf.Language(28), 7000)
return return
@ -182,7 +182,7 @@ func syncData(exit, byHand bool) {
} }
util.BroadcastByType("main", "syncing", 0, Conf.Language(81), nil) util.BroadcastByType("main", "syncing", 0, Conf.Language(81), nil)
if !exit && !isProviderOnline() { // 这个操作比较耗时,所以要先推送 syncing 事件后再判断网络,这样才能给用户更即时的反馈 if !exit && !isProviderOnline(byHand) { // 这个操作比较耗时,所以要先推送 syncing 事件后再判断网络,这样才能给用户更即时的反馈
util.BroadcastByType("main", "syncing", 2, Conf.Language(28), nil) util.BroadcastByType("main", "syncing", 2, Conf.Language(28), nil)
return return
} }
@ -250,8 +250,8 @@ func checkSync(boot, exit, byHand bool) bool {
return false return false
} }
if 7 < syncDownloadErrCount && !byHand { if 7 < autoSyncErrCount && !byHand {
logging.LogErrorf("sync download error too many times, cancel auto sync, try to sync by hand") logging.LogErrorf("failed to auto-sync too many times, delay auto-sync 64 minutes")
util.PushErrMsg(Conf.Language(125), 1000*60*60) util.PushErrMsg(Conf.Language(125), 1000*60*60)
planSyncAfter(64 * time.Minute) planSyncAfter(64 * time.Minute)
return false return false
@ -561,7 +561,7 @@ func planSyncAfter(d time.Duration) {
syncPlanTime = time.Now().Add(d) syncPlanTime = time.Now().Add(d)
} }
func isProviderOnline() (ret bool) { func isProviderOnline(byHand bool) (ret bool) {
checkURL := util.SiYuanSyncServer checkURL := util.SiYuanSyncServer
skipTlsVerify := false skipTlsVerify := false
switch Conf.Sync.Provider { switch Conf.Sync.Provider {
@ -578,7 +578,9 @@ func isProviderOnline() (ret bool) {
} }
if ret = util.IsOnline(checkURL, skipTlsVerify); !ret { if ret = util.IsOnline(checkURL, skipTlsVerify); !ret {
util.PushErrMsg(Conf.Language(76) + " (Provider: " + conf.ProviderToStr(Conf.Sync.Provider) + ")", 5000) if 1 > autoSyncErrCount || byHand {
util.PushErrMsg(Conf.Language(76)+" (Provider: "+conf.ProviderToStr(Conf.Sync.Provider)+")", 5000)
}
} }
return return
} }