فهرست منبع

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

Simon Frei 6 سال پیش
والد
کامیت
22e133cce6
2فایلهای تغییر یافته به همراه9 افزوده شده و 4 حذف شده
  1. 8 3
      lib/db/instance.go
  2. 1 1
      lib/db/set.go

+ 8 - 3
lib/db/instance.go

@@ -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()
+}

+ 1 - 1
lib/db/set.go

@@ -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
 		}