lib/db: Deduplicate comparing old and new items (#5465)
This commit is contained in:
parent
a80c0fdae8
commit
22e133cce6
@ -48,9 +48,7 @@ func (db *instance) updateFiles(folder, device []byte, fs []protocol.FileInfo, m
|
|||||||
err = ef.Unmarshal(bs)
|
err = ef.Unmarshal(bs)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Local flags or the invalid bit might change without the version
|
if err == nil && unchanged(f, ef) {
|
||||||
// being bumped. The IsInvalid() method handles both.
|
|
||||||
if err == nil && ef.Version.Equal(f.Version) && ef.IsInvalid() == f.IsInvalid() {
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -563,3 +561,10 @@ type errorSuggestion struct {
|
|||||||
func (e errorSuggestion) Error() string {
|
func (e errorSuggestion) Error() string {
|
||||||
return fmt.Sprintf("%s (%s)", e.inner.Error(), e.suggestion)
|
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()
|
||||||
|
}
|
||||||
|
|||||||
@ -164,7 +164,7 @@ func (s *FileSet) Update(device protocol.DeviceID, fs []protocol.FileInfo) {
|
|||||||
folder := []byte(s.folder)
|
folder := []byte(s.folder)
|
||||||
for _, nf := range oldFs {
|
for _, nf := range oldFs {
|
||||||
ef, ok := s.db.getFileDirty(folder, device[:], []byte(osutil.NormalizedFilename(nf.Name)))
|
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
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user