mirror of
https://github.com/octoleo/syncthing.git
synced 2024-11-09 23:00:58 +00:00
Revert "Merge branch 'pr/711'" (...)
Temporary revert to the old debounce behavior. It's a bit bad and drives up CPU usage, but mostly shows correct info in the GUI. This will be improved shortly. This reverts commit5144330807
, reversing changes made toc34f3defe1
. Conflicts: auto/gui.files.go
This commit is contained in:
parent
a502836002
commit
b0b34236e3
File diff suppressed because one or more lines are too long
129
gui/app.js
129
gui/app.js
@ -9,9 +9,6 @@
|
|||||||
|
|
||||||
var syncthing = angular.module('syncthing', ['pascalprecht.translate']);
|
var syncthing = angular.module('syncthing', ['pascalprecht.translate']);
|
||||||
var urlbase = 'rest';
|
var urlbase = 'rest';
|
||||||
var requestTimeout = 300000; // Retry the REST request after 5 minutes without reply
|
|
||||||
var refreshTimeout = 5000; // Do not refresh the generic status faster than 5 seconds
|
|
||||||
var refreshQuickTimeout = 500; // Do not refresh the quick stats faster than 500 milliseconds
|
|
||||||
|
|
||||||
syncthing.config(function ($httpProvider, $translateProvider) {
|
syncthing.config(function ($httpProvider, $translateProvider) {
|
||||||
$httpProvider.defaults.xsrfHeaderName = 'X-CSRF-Token';
|
$httpProvider.defaults.xsrfHeaderName = 'X-CSRF-Token';
|
||||||
@ -252,19 +249,19 @@ syncthing.controller('SyncthingCtrl', function ($scope, $http, $translate, $loca
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
var nextCall = {};
|
var debouncedFuncs = {};
|
||||||
|
|
||||||
function refreshRepo(repo) {
|
function refreshRepo(repo) {
|
||||||
var key = "refreshRepo" + repo;
|
var key = "refreshRepo" + repo;
|
||||||
if (nextCall[key] && nextCall[key] > Date.now()) {
|
if (!debouncedFuncs[key]) {
|
||||||
return;
|
debouncedFuncs[key] = debounce(function () {
|
||||||
|
$http.get(urlbase + '/model?repo=' + encodeURIComponent(repo)).success(function (data) {
|
||||||
|
$scope.model[repo] = data;
|
||||||
|
console.log("refreshRepo", repo, data);
|
||||||
|
});
|
||||||
|
}, 1000, true);
|
||||||
}
|
}
|
||||||
nextCall[key] = Date.now() + requestTimeout;
|
debouncedFuncs[key]();
|
||||||
$http.get(urlbase + '/model?repo=' + encodeURIComponent(repo)).success(function (data) {
|
|
||||||
nextCall[key] = Date.now() + refreshTimeout;
|
|
||||||
$scope.model[repo] = data;
|
|
||||||
console.log("refreshRepo", repo, data);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateLocalConfig(config) {
|
function updateLocalConfig(config) {
|
||||||
@ -295,13 +292,7 @@ syncthing.controller('SyncthingCtrl', function ($scope, $http, $translate, $loca
|
|||||||
}
|
}
|
||||||
|
|
||||||
function refreshSystem() {
|
function refreshSystem() {
|
||||||
var key = "refreshSystem"
|
|
||||||
if (nextCall[key] && nextCall[key] > Date.now()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
nextCall[key] = Date.now() + requestTimeout;
|
|
||||||
$http.get(urlbase + '/system').success(function (data) {
|
$http.get(urlbase + '/system').success(function (data) {
|
||||||
nextCall[key] = Date.now() + refreshQuickTimeout;
|
|
||||||
$scope.myID = data.myID;
|
$scope.myID = data.myID;
|
||||||
$scope.system = data;
|
$scope.system = data;
|
||||||
console.log("refreshSystem", data);
|
console.log("refreshSystem", data);
|
||||||
@ -314,40 +305,34 @@ syncthing.controller('SyncthingCtrl', function ($scope, $http, $translate, $loca
|
|||||||
}
|
}
|
||||||
|
|
||||||
var key = "refreshCompletion" + node + repo;
|
var key = "refreshCompletion" + node + repo;
|
||||||
if (nextCall[key] && nextCall[key] > Date.now()) {
|
if (!debouncedFuncs[key]) {
|
||||||
return;
|
debouncedFuncs[key] = debounce(function () {
|
||||||
|
$http.get(urlbase + '/completion?node=' + node + '&repo=' + encodeURIComponent(repo)).success(function (data) {
|
||||||
|
if (!$scope.completion[node]) {
|
||||||
|
$scope.completion[node] = {};
|
||||||
|
}
|
||||||
|
$scope.completion[node][repo] = data.completion;
|
||||||
|
|
||||||
|
var tot = 0,
|
||||||
|
cnt = 0;
|
||||||
|
for (var cmp in $scope.completion[node]) {
|
||||||
|
if (cmp === "_total") {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
tot += $scope.completion[node][cmp];
|
||||||
|
cnt += 1;
|
||||||
|
}
|
||||||
|
$scope.completion[node]._total = tot / cnt;
|
||||||
|
|
||||||
|
console.log("refreshCompletion", node, repo, $scope.completion[node]);
|
||||||
|
});
|
||||||
|
}, 1000, true);
|
||||||
}
|
}
|
||||||
nextCall[key] = Date.now() + requestTimeout;
|
debouncedFuncs[key]();
|
||||||
$http.get(urlbase + '/completion?node=' + node + '&repo=' + encodeURIComponent(repo)).success(function (data) {
|
|
||||||
nextCall[key] = Date.now() + refreshTimeout;
|
|
||||||
if (!$scope.completion[node]) {
|
|
||||||
$scope.completion[node] = {};
|
|
||||||
}
|
|
||||||
$scope.completion[node][repo] = data.completion;
|
|
||||||
|
|
||||||
var tot = 0,
|
|
||||||
cnt = 0;
|
|
||||||
for (var cmp in $scope.completion[node]) {
|
|
||||||
if (cmp === "_total") {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
tot += $scope.completion[node][cmp];
|
|
||||||
cnt += 1;
|
|
||||||
}
|
|
||||||
$scope.completion[node]._total = tot / cnt;
|
|
||||||
|
|
||||||
console.log("refreshCompletion", node, repo, $scope.completion[node]);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function refreshConnectionStats() {
|
function refreshConnectionStats() {
|
||||||
var key = "refreshConnectionStats"
|
|
||||||
if (nextCall[key] && nextCall[key] > Date.now()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
nextCall[key] = Date.now() + requestTimeout;
|
|
||||||
$http.get(urlbase + '/connections').success(function (data) {
|
$http.get(urlbase + '/connections').success(function (data) {
|
||||||
nextCall[key] = Date.now() + refreshQuickTimeout;
|
|
||||||
var now = Date.now(),
|
var now = Date.now(),
|
||||||
td = (now - prevDate) / 1000,
|
td = (now - prevDate) / 1000,
|
||||||
id;
|
id;
|
||||||
@ -371,13 +356,7 @@ syncthing.controller('SyncthingCtrl', function ($scope, $http, $translate, $loca
|
|||||||
}
|
}
|
||||||
|
|
||||||
function refreshErrors() {
|
function refreshErrors() {
|
||||||
var key = "refreshErrors"
|
|
||||||
if (nextCall[key] && nextCall[key] > Date.now()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
nextCall[key] = Date.now() + requestTimeout;
|
|
||||||
$http.get(urlbase + '/errors').success(function (data) {
|
$http.get(urlbase + '/errors').success(function (data) {
|
||||||
nextCall[key] = Date.now() + refreshQuickTimeout;
|
|
||||||
$scope.errors = data.errors;
|
$scope.errors = data.errors;
|
||||||
console.log("refreshErrors", data);
|
console.log("refreshErrors", data);
|
||||||
});
|
});
|
||||||
@ -394,14 +373,8 @@ syncthing.controller('SyncthingCtrl', function ($scope, $http, $translate, $loca
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
var refreshNodeStats = function () {
|
var refreshNodeStats = debounce(function () {
|
||||||
var key = "refreshNode";
|
|
||||||
if (nextCall[key] && nextCall[key] > Date.now()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
nextCall[key] = Date.now() + requestTimeout;
|
|
||||||
$http.get(urlbase + "/stats/node").success(function (data) {
|
$http.get(urlbase + "/stats/node").success(function (data) {
|
||||||
nextCall[key] = Date.now() + refreshTimeout;
|
|
||||||
$scope.stats = data;
|
$scope.stats = data;
|
||||||
for (var node in $scope.stats) {
|
for (var node in $scope.stats) {
|
||||||
$scope.stats[node].LastSeen = new Date($scope.stats[node].LastSeen);
|
$scope.stats[node].LastSeen = new Date($scope.stats[node].LastSeen);
|
||||||
@ -409,7 +382,7 @@ syncthing.controller('SyncthingCtrl', function ($scope, $http, $translate, $loca
|
|||||||
}
|
}
|
||||||
console.log("refreshNodeStats", data);
|
console.log("refreshNodeStats", data);
|
||||||
});
|
});
|
||||||
}
|
}, 500);
|
||||||
|
|
||||||
$scope.init = function () {
|
$scope.init = function () {
|
||||||
refreshSystem();
|
refreshSystem();
|
||||||
@ -1061,6 +1034,40 @@ function isEmptyObject(obj) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function debounce(func, wait) {
|
||||||
|
var timeout, args, context, timestamp, result, again;
|
||||||
|
|
||||||
|
var later = function () {
|
||||||
|
var last = Date.now() - timestamp;
|
||||||
|
if (last < wait) {
|
||||||
|
timeout = setTimeout(later, wait - last);
|
||||||
|
} else {
|
||||||
|
timeout = null;
|
||||||
|
if (again) {
|
||||||
|
again = false;
|
||||||
|
result = func.apply(context, args);
|
||||||
|
context = args = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return function () {
|
||||||
|
context = this;
|
||||||
|
args = arguments;
|
||||||
|
timestamp = Date.now();
|
||||||
|
var callNow = !timeout;
|
||||||
|
if (!timeout) {
|
||||||
|
timeout = setTimeout(later, wait);
|
||||||
|
result = func.apply(context, args);
|
||||||
|
context = args = null;
|
||||||
|
} else {
|
||||||
|
again = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
syncthing.filter('natural', function () {
|
syncthing.filter('natural', function () {
|
||||||
return function (input, valid) {
|
return function (input, valid) {
|
||||||
return input.toFixed(decimals(input, valid));
|
return input.toFixed(decimals(input, valid));
|
||||||
|
Loading…
Reference in New Issue
Block a user