Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
88250 committed Oct 30, 2023
1 parent cbb9386 commit 4dce9cc
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 14 deletions.
10 changes: 7 additions & 3 deletions diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
package dejavu

import (
"time"

"github.com/siyuan-note/dejavu/entity"
"github.com/siyuan-note/logging"
)
Expand All @@ -37,15 +39,17 @@ func (repo *Repo) DiffUpsertRemove(left, right []*entity.File, log bool) (upsert
if nil == rFile {
upserts = append(upserts, l[lPath])
if log {
logging.LogInfof("upsert [path=%s, updated=%d]", l[lPath].Path, l[lPath].Updated)
logging.LogInfof("upsert [path=%s, updated=%s]", l[lPath].Path, time.UnixMilli(l[lPath].Updated).Format("2006-01-02 15:04:05"))
}

continue
}
if !equalFile(lFile, rFile) {
upserts = append(upserts, l[lPath])
if log {
logging.LogInfof("upsert [lPath=%s, lUpdated=%d, rPath=%s, rUpdated=%d]", l[lPath].Path, l[lPath].Updated, rFile.Path, rFile.Updated)
logging.LogInfof("upsert [lPath=%s, lUpdated=%s, rPath=%s, rUpdated=%s]",
l[lPath].Path, time.UnixMilli(l[lPath].Updated).Format("2006-01-02 15:04:05"),
rFile.Path, time.UnixMilli(rFile.Updated).Format("2006-01-02 15:04:05"))
}
continue
}
Expand All @@ -56,7 +60,7 @@ func (repo *Repo) DiffUpsertRemove(left, right []*entity.File, log bool) (upsert
if nil == lFile {
removes = append(removes, r[rPath])
if log {
logging.LogInfof("remove [path=%s, updated=%d]", r[rPath].Path, r[rPath].Updated)
logging.LogInfof("remove [path=%s, updated=%s]", r[rPath].Path, time.UnixMilli(r[rPath].Updated).Format("2006-01-02 15:04:05"))
}
continue
}
Expand Down
4 changes: 2 additions & 2 deletions repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,8 +309,8 @@ func (repo *Repo) index(memo string, context map[string]interface{}) (ret *entit
// Check local data chunk integrity before data synchronization https://github.com/siyuan-note/siyuan/issues/8853
for _, chunk := range file.Chunks {
if _, statErr := repo.store.Stat(chunk); nil != statErr {
logging.LogErrorf("stat file [path=%s, size=%d, updated=%d] chunk [%s] failed: %s",
file.Path, file.Size, file.Updated, chunk, statErr)
logging.LogErrorf("stat file [path=%s, size=%d, updated=%s] chunk [%s] failed: %s",
file.Path, file.Size, time.UnixMilli(file.Updated).Format("2006-01-02 15:04:05"), chunk, statErr)
workerErrLock.Lock()
workerErrs = append(workerErrs, ErrNotFoundObject)
workerErrLock.Unlock()
Expand Down
18 changes: 9 additions & 9 deletions sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,16 +231,16 @@ func (repo *Repo) sync0(context map[string]interface{},

// 增加一些诊断日志 https://ld246.com/article/1698370932077
for _, c := range cloudUpserts {
logging.LogInfof("cloud upsert [%s, %d]", c.Path, c.Updated)
logging.LogInfof("cloud upsert [%s, %s]", c.Path, time.UnixMilli(c.Updated).Format("2006-01-02 15:04:05"))
}
for _, r := range cloudRemoves {
logging.LogInfof("cloud remove [%s, %d]", r.Path, r.Updated)
logging.LogInfof("cloud remove [%s, %s]", r.Path, time.UnixMilli(r.Updated).Format("2006-01-02 15:04:05"))
}
for _, c := range localUpserts {
logging.LogInfof("local upsert [%s, %d]", c.Path, c.Updated)
logging.LogInfof("local upsert [%s, %s]", c.Path, time.UnixMilli(c.Updated).Format("2006-01-02 15:04:05"))
}
for _, r := range localRemoves {
logging.LogInfof("local remove [%s, %d]", r.Path, r.Updated)
logging.LogInfof("local remove [%s, %s]", r.Path, time.UnixMilli(r.Updated).Format("2006-01-02 15:04:05"))
}

// 避免旧的本地数据覆盖云端数据 https://github.com/siyuan-note/siyuan/issues/7403
Expand Down Expand Up @@ -288,7 +288,7 @@ func (repo *Repo) sync0(context map[string]interface{},
continue
}
mergeResult.Upserts = append(mergeResult.Upserts, cloudUpsert)
logging.LogInfof("sync merge upsert [path=%s, updated=%d]", cloudUpsert.Path, cloudUpsert.Updated)
logging.LogInfof("sync merge upsert [path=%s, updated=%s]", cloudUpsert.Path, time.UnixMilli(cloudUpsert.Updated).Format("2006-01-02 15:04:05"))
}
}

Expand Down Expand Up @@ -556,8 +556,8 @@ func (repo *Repo) filterLocalUpserts(localUpserts, cloudUpserts []*entity.File)
if cloudUpsert := cloudUpsertsMap[localUpsert.Path]; nil != cloudUpsert {
if localUpsert.Updated < cloudUpsert.Updated-1000*60*7 { // 本地早于云端 7 分钟
toRemoveLocalUpsertPaths = append(toRemoveLocalUpsertPaths, localUpsert.Path) // 使用云端数据覆盖本地数据
logging.LogWarnf("ignored local upsert [%s, %d] because it is older than cloud upsert [%s, %d]",
localUpsert.Path, localUpsert.Updated, cloudUpsert.Path, cloudUpsert.Updated)
logging.LogWarnf("ignored local upsert [%s, %s] because it is older than cloud upsert [%s, %s]",
localUpsert.Path, time.UnixMilli(localUpsert.Updated).Format("2006-01-02 15:04:05"), cloudUpsert.Path, time.UnixMilli(cloudUpsert.Updated).Format("2006-01-02 15:04:05"))
}
}
}
Expand All @@ -572,11 +572,11 @@ func (repo *Repo) filterLocalUpserts(localUpserts, cloudUpserts []*entity.File)
buf := bytes.Buffer{}
buf.WriteString("filtered local upserts from:\n")
for _, localUpsert := range localUpserts {
buf.WriteString(fmt.Sprintf(" [%s, %d]\n", localUpsert.Path, localUpsert.Updated))
buf.WriteString(fmt.Sprintf(" [%s, %s]\n", localUpsert.Path, time.UnixMilli(localUpsert.Updated).Format("2006-01-02 15:04:05")))
}
buf.WriteString("to:\n")
for _, localUpsert := range ret {
buf.WriteString(fmt.Sprintf(" [%s, %d]\n", localUpsert.Path, localUpsert.Updated))
buf.WriteString(fmt.Sprintf(" [%s, %s]\n", localUpsert.Path, time.UnixMilli(localUpsert.Updated).Format("2006-01-02 15:04:05")))
}
if 1 > len(ret) {
buf.WriteString(" []")
Expand Down

0 comments on commit 4dce9cc

Please sign in to comment.