WebUI: Prevent excessive sync requests

Don't sync main data if a request to do so is already in progress.

This prevents piling up of requests and bogging down slow/busy machines, since the current implementation of `/api/v2/sync/maindata` is very computationally intensive, especially with lots of torrents.

Everything gets updated on the next scheduled request anyway (via the timeout mechanism).
This commit is contained in:
FranciscoPombal 2019-12-29 14:19:27 +00:00
commit d4f49c3666

View file

@ -41,6 +41,7 @@ var queueing_enabled = true;
var serverSyncMainDataInterval = 1500;
var customSyncMainDataInterval = null;
let syncRequestInProgress = false;
var clipboardEvent;
var CATEGORIES_ALL = 1;
@ -334,7 +335,7 @@ window.addEvent('load', function() {
var syncMainData = function() {
var url = new URI('api/v2/sync/maindata');
url.setData('rid', syncMainDataLastResponseId);
new Request.JSON({
const request = new Request.JSON({
url: url,
noCache: true,
method: 'get',
@ -342,8 +343,8 @@ window.addEvent('load', function() {
var errorDiv = $('error_div');
if (errorDiv)
errorDiv.set('html', 'QBT_TR(qBittorrent client is not reachable)QBT_TR[CONTEXT=HttpServer]');
clearTimeout(syncMainDataTimer);
syncMainDataTimer = syncMainData.delay(2000);
syncRequestInProgress = false;
syncData(2000);
},
onSuccess: function(response) {
$('error_div').set('html', '');
@ -426,18 +427,26 @@ window.addEvent('load', function() {
// re-select previously selected rows
torrentsTable.reselectRows(torrentsTableSelectedRows);
}
clearTimeout(syncMainDataTimer);
syncMainDataTimer = syncMainData.delay(getSyncMainDataInterval());
syncRequestInProgress = false;
syncData(getSyncMainDataInterval())
}
}).send();
});
syncRequestInProgress = true;
request.send();
};
updateMainData = function() {
torrentsTable.updateTable();
clearTimeout(syncMainDataTimer);
syncMainDataTimer = syncMainData.delay(100);
syncData(100);
};
const syncData = function(delay) {
if (!syncRequestInProgress){
clearTimeout(syncMainDataTimer);
syncMainDataTimer = syncMainData.delay(delay);
}
}
var processServerState = function() {
var transfer_info = friendlyUnit(serverState.dl_info_speed, true);
if (serverState.dl_rate_limit > 0)
@ -607,8 +616,7 @@ window.addEvent('load', function() {
$("mainColumn").removeClass("invisible");
customSyncMainDataInterval = null;
clearTimeout(syncMainDataTimer);
syncMainDataTimer = syncMainData.delay(100);
syncData(100);
hideSearchTab();
};