[WebUI] use setTimeout instead of setInterval

When server is busy or the request is slow for big file list, WebUI still
requests for new update blindly. "Connection lost" is often triggerd.

Change to only ask for update 2s after reponse (either success or error)

Signed-off-by: Xuefer H <xuefer@gmail.com>
Closes: https://github.com/deluge-torrent/deluge/pull/416
This commit is contained in:
Xuefer H 2023-04-11 16:16:37 +08:00 committed by Calum Lind
parent 39bd97f03e
commit 71b634e968
No known key found for this signature in database
GPG Key ID: 90597A687B836BA3
2 changed files with 42 additions and 10 deletions

View File

@ -162,13 +162,23 @@ Deluge.ConnectionManager = Ext.extend(Ext.Window, {
},
update: function () {
this.updating = setTimeout(this.update, 2000);
this.list.getStore().each(function (r) {
deluge.client.web.get_host_status(r.id, {
success: this.onGetHostStatus,
success: this.onUpdate,
scope: this,
});
}, this);
},
onUpdate: function (host) {
if (!this.isVisible()) return;
this.onGetHostStatus(host);
if (this.updating) {
clearTimeout(this.updating);
}
this.updating = setTimeout(this.update, 2000);
},
/**
* Updates the buttons in the Connection Manager UI according to the
@ -312,7 +322,10 @@ Deluge.ConnectionManager = Ext.extend(Ext.Window, {
// private
onHide: function () {
if (this.running) window.clearInterval(this.running);
if (this.updating) {
window.clearTimeout(this.updating);
this.updating = undefined;
}
},
// private
@ -396,8 +409,8 @@ Deluge.ConnectionManager = Ext.extend(Ext.Window, {
this.stopHostButton = bbar.items.get('cm-stop');
}
this.loadHosts();
if (this.running) return;
this.running = window.setInterval(this.update, 2000, this);
if (this.updating) return;
this.updating = window.setTimeout(this.update, 2000);
},
// private

View File

@ -134,14 +134,24 @@ deluge.ui = {
deluge.details.update();
},
onConnectionError: function (error) {},
onConnectionError: function (error) {
if (this.checking) {
clearTimeout(this.checking);
}
this.checking = setTimeout(this.checkConnection, 2000);
},
onConnectionSuccess: function (result) {
if (this.checking) {
clearTimeout(this.checking);
this.checking = undefined;
}
this.running = setTimeout(this.update, 2000);
this.update();
deluge.statusbar.setStatus({
iconCls: 'x-deluge-statusbar icon-ok',
text: _('Connection restored'),
});
clearInterval(this.checking);
if (!result) {
deluge.connectionManager.show();
}
@ -159,9 +169,13 @@ deluge.ui = {
deluge.statusbar.setStatus({
text: _('Lost connection to webserver'),
});
this.checking = setInterval(this.checkConnection, 2000);
this.checking = setTimeout(this.checkConnection, 2000);
}
this.errorCount++;
if (this.running) {
clearTimeout(this.running);
this.running = undefined;
}
},
/**
@ -170,10 +184,15 @@ deluge.ui = {
* Updates the various components in the interface.
*/
onUpdate: function (data) {
if (this.running) {
clearTimeout(this.running);
this.running = undefined;
}
if (!data['connected']) {
deluge.connectionManager.disconnect(true);
return;
}
this.running = setTimeout(this.update, 2000);
if (deluge.config.show_session_speed) {
document.title =
@ -201,7 +220,7 @@ deluge.ui = {
*/
onConnect: function () {
if (!this.running) {
this.running = setInterval(this.update, 2000);
this.running = setTimeout(this.update, 2000);
this.update();
}
deluge.client.web.get_plugins({
@ -280,8 +299,8 @@ deluge.ui = {
*/
stop: function () {
if (this.running) {
clearInterval(this.running);
this.running = false;
clearTimeout(this.running);
this.running = undefined;
deluge.torrents.getStore().removeAll();
}
},