mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-01-26 22:44:36 +00:00
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:
parent
18de63f743
commit
0f6dfcf8a6
@ -35,6 +35,8 @@ let serverSyncMainDataInterval = 1500;
|
|||||||
let customSyncMainDataInterval = null;
|
let customSyncMainDataInterval = null;
|
||||||
let searchTabInitialized = false;
|
let searchTabInitialized = false;
|
||||||
|
|
||||||
|
let syncRequestInProgress = false;
|
||||||
|
|
||||||
let clipboardEvent;
|
let clipboardEvent;
|
||||||
|
|
||||||
const CATEGORIES_ALL = 1;
|
const CATEGORIES_ALL = 1;
|
||||||
@ -458,7 +460,7 @@ window.addEvent('load', function() {
|
|||||||
const syncMainData = function() {
|
const syncMainData = function() {
|
||||||
const url = new URI('api/v2/sync/maindata');
|
const url = new URI('api/v2/sync/maindata');
|
||||||
url.setData('rid', syncMainDataLastResponseId);
|
url.setData('rid', syncMainDataLastResponseId);
|
||||||
new Request.JSON({
|
const request = new Request.JSON({
|
||||||
url: url,
|
url: url,
|
||||||
noCache: true,
|
noCache: true,
|
||||||
method: 'get',
|
method: 'get',
|
||||||
@ -466,8 +468,8 @@ window.addEvent('load', function() {
|
|||||||
const errorDiv = $('error_div');
|
const errorDiv = $('error_div');
|
||||||
if (errorDiv)
|
if (errorDiv)
|
||||||
errorDiv.set('html', 'QBT_TR(qBittorrent client is not reachable)QBT_TR[CONTEXT=HttpServer]');
|
errorDiv.set('html', 'QBT_TR(qBittorrent client is not reachable)QBT_TR[CONTEXT=HttpServer]');
|
||||||
clearTimeout(syncMainDataTimer);
|
syncRequestInProgress = false;
|
||||||
syncMainDataTimer = syncMainData.delay(2000);
|
syncData(2000);
|
||||||
},
|
},
|
||||||
onSuccess: function(response) {
|
onSuccess: function(response) {
|
||||||
$('error_div').set('html', '');
|
$('error_div').set('html', '');
|
||||||
@ -579,18 +581,26 @@ window.addEvent('load', function() {
|
|||||||
// re-select previously selected rows
|
// re-select previously selected rows
|
||||||
torrentsTable.reselectRows(torrentsTableSelectedRows);
|
torrentsTable.reselectRows(torrentsTableSelectedRows);
|
||||||
}
|
}
|
||||||
clearTimeout(syncMainDataTimer);
|
syncRequestInProgress = false;
|
||||||
syncMainDataTimer = syncMainData.delay(getSyncMainDataInterval());
|
syncData(getSyncMainDataInterval())
|
||||||
}
|
}
|
||||||
}).send();
|
});
|
||||||
|
syncRequestInProgress = true;
|
||||||
|
request.send();
|
||||||
};
|
};
|
||||||
|
|
||||||
updateMainData = function() {
|
updateMainData = function() {
|
||||||
torrentsTable.updateTable();
|
torrentsTable.updateTable();
|
||||||
clearTimeout(syncMainDataTimer);
|
syncData(100);
|
||||||
syncMainDataTimer = syncMainData.delay(100);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const syncData = function(delay) {
|
||||||
|
if (!syncRequestInProgress){
|
||||||
|
clearTimeout(syncMainDataTimer);
|
||||||
|
syncMainDataTimer = syncMainData.delay(delay);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const processServerState = function() {
|
const processServerState = function() {
|
||||||
let transfer_info = window.qBittorrent.Misc.friendlyUnit(serverState.dl_info_speed, true);
|
let transfer_info = window.qBittorrent.Misc.friendlyUnit(serverState.dl_info_speed, true);
|
||||||
if (serverState.dl_rate_limit > 0)
|
if (serverState.dl_rate_limit > 0)
|
||||||
@ -764,8 +774,7 @@ window.addEvent('load', function() {
|
|||||||
$("mainColumn").removeClass("invisible");
|
$("mainColumn").removeClass("invisible");
|
||||||
|
|
||||||
customSyncMainDataInterval = null;
|
customSyncMainDataInterval = null;
|
||||||
clearTimeout(syncMainDataTimer);
|
syncData(100);
|
||||||
syncMainDataTimer = syncMainData.delay(100);
|
|
||||||
|
|
||||||
hideSearchTab();
|
hideSearchTab();
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user