lib/db: Deduplicate comparing old and new items (#5465)

This commit is contained in:
Simon Frei 2019-01-18 22:19:56 +01:00 committed by Audrius Butkevicius
parent a80c0fdae8
commit 22e133cce6
2 changed files with 9 additions and 4 deletions

View File

@ -48,9 +48,7 @@ func (db *instance) updateFiles(folder, device []byte, fs []protocol.FileInfo, m
err = ef.Unmarshal(bs)
}
// Local flags or the invalid bit might change without the version
// being bumped. The IsInvalid() method handles both.
if err == nil && ef.Version.Equal(f.Version) && ef.IsInvalid() == f.IsInvalid() {
if err == nil && unchanged(f, ef) {
continue
}
@ -563,3 +561,10 @@ type errorSuggestion struct {
func (e errorSuggestion) Error() string {
return fmt.Sprintf("%s (%s)", e.inner.Error(), e.suggestion)
}
// unchanged checks if two files are the same and thus don't need to be updated.
// Local flags or the invalid bit might change without the version
// being bumped. The IsInvalid() method handles both.
func unchanged(nf, ef FileIntf) bool {
return ef.FileVersion().Equal(nf.FileVersion()) && ef.IsInvalid() == nf.IsInvalid()
}

View File

@ -164,7 +164,7 @@ func (s *FileSet) Update(device protocol.DeviceID, fs []protocol.FileInfo) {
folder := []byte(s.folder)
for _, nf := range oldFs {
ef, ok := s.db.getFileDirty(folder, device[:], []byte(osutil.NormalizedFilename(nf.Name)))
if ok && ef.Version.Equal(nf.Version) && ef.IsInvalid() == nf.IsInvalid() {
if ok && unchanged(nf, ef) {
continue
}