Преглед на файлове

gui: weighting % of devices according to folder size (fixes #1300)

The completion of remote devices was based only on the average of the percentages of all folders, which is irrelevant in case of two folders with very different sizes.

GitHub-Pull-Request: https://github.com/syncthing/syncthing/pull/3481
LGTM: calmh, AudriusButkevicius
Antoine Lamielle преди 9 години
родител
ревизия
c9cf01e0b6
променени са 1 файла, в които са добавени 28 реда и са изтрити 8 реда
  1. 28 8
      gui/default/syncthing/core/syncthingController.js

+ 28 - 8
gui/default/syncthing/core/syncthingController.js

@@ -312,15 +312,25 @@ angular.module('syncthing.core')
             $scope.completion[data.device][data.folder] = data.completion;
             $scope.completion[data.device][data.folder] = data.completion;
 
 
             var tot = 0,
             var tot = 0,
-                cnt = 0;
+                cnt = 0,
+                isComplete = true;
             for (var cmp in $scope.completion[data.device]) {
             for (var cmp in $scope.completion[data.device]) {
                 if (cmp === "_total") {
                 if (cmp === "_total") {
                     continue;
                     continue;
                 }
                 }
-                tot += $scope.completion[data.device][cmp];
-                cnt += 1;
+                tot += $scope.completion[data.device][cmp] * $scope.model[cmp].globalBytes;
+                cnt += $scope.model[cmp].globalBytes;
+                if ($scope.completion[data.device][cmp] != 100) {
+                    isComplete = false;
+                }
+            }
+            //To be sure that we won't get any rounding errors resulting in non-100% status when it should be
+            if (isComplete) {
+                $scope.completion[data.device]._total = 100;
+            }
+            else {
+                $scope.completion[data.device]._total = tot / cnt;
             }
             }
-            $scope.completion[data.device]._total = tot / cnt;
         });
         });
 
 
         $scope.$on(Events.FOLDER_ERRORS, function (event, arg) {
         $scope.$on(Events.FOLDER_ERRORS, function (event, arg) {
@@ -460,15 +470,25 @@ angular.module('syncthing.core')
                 $scope.completion[device][folder] = data.completion;
                 $scope.completion[device][folder] = data.completion;
 
 
                 var tot = 0,
                 var tot = 0,
-                    cnt = 0;
+                    cnt = 0,
+                    isComplete = true;
                 for (var cmp in $scope.completion[device]) {
                 for (var cmp in $scope.completion[device]) {
                     if (cmp === "_total") {
                     if (cmp === "_total") {
                         continue;
                         continue;
                     }
                     }
-                    tot += $scope.completion[device][cmp];
-                    cnt += 1;
+                    tot += $scope.completion[device][cmp] * $scope.model[cmp].globalBytes;
+                    cnt += $scope.model[cmp].globalBytes;
+                    if ($scope.completion[device][cmp] != 100) {
+                        isComplete = false;
+                    }
+                }
+                //To be sure that we won't get any rounding errors resulting in non-100% status when it should be
+                if (isComplete) {
+                    $scope.completion[device]._total = 100;
+                }
+                else {
+                    $scope.completion[device]._total = tot / cnt;
                 }
                 }
-                $scope.completion[device]._total = tot / cnt;
 
 
                 console.log("refreshCompletion", device, folder, $scope.completion[device]);
                 console.log("refreshCompletion", device, folder, $scope.completion[device]);
             }).error($scope.emitHTTPError);
             }).error($scope.emitHTTPError);