diff --git a/assets/js/app.js b/assets/js/app.js index 32d4992..1ce52fe 100644 --- a/assets/js/app.js +++ b/assets/js/app.js @@ -62,8 +62,6 @@ export class App { initTasks () { this._taskIds.push(setInterval(this.sortController.sortServers, 5000)) - this._taskIds.push(setInterval(this.updateGlobalStats, 1000)) - this._taskIds.push(setInterval(this.percentageBar.redraw, 1000)) } handleDisconnect () { diff --git a/assets/js/graph.js b/assets/js/graph.js index 058b10d..9c88a11 100644 --- a/assets/js/graph.js +++ b/assets/js/graph.js @@ -161,18 +161,6 @@ export class GraphDisplayManager { document.getElementById('settings-toggle').style.display = 'inline-block' } - // requestRedraw allows usages to request a redraw that may be performed, or cancelled, sometime later - // This allows multiple rapid, but individual updates, to clump into a single redraw instead - requestRedraw () { - if (this._redrawRequestTimeout) { - clearTimeout(this._redrawRequestTimeout) - } - - // Schedule new delayed redraw call - // This can be cancelled by #requestRedraw, #redraw and #reset - this._redrawRequestTimeout = setTimeout(this.redraw, 1000) - } - redraw = () => { // Use drawing as a hint to update settings // This may cause unnessecary localStorage updates, but its a rare and harmless outcome @@ -183,14 +171,6 @@ export class GraphDisplayManager { this._plotInstance.setData(this.getVisibleGraphData()) this._plotInstance.setupGrid() this._plotInstance.draw() - - // undefine value so #clearTimeout is not called - // This is safe even if #redraw is manually called since it removes the pending work - if (this._redrawRequestTimeout) { - clearTimeout(this._redrawRequestTimeout) - } - - this._redrawRequestTimeout = undefined } requestResize () { @@ -348,12 +328,6 @@ export class GraphDisplayManager { this._resizeRequestTimeout = undefined } - if (this._redrawRequestTimeout) { - clearTimeout(this._redrawRequestTimeout) - - this._redrawRequestTimeout = undefined - } - // Reset modified DOM structures document.getElementById('big-graph-checkboxes').innerHTML = '' document.getElementById('big-graph-controls').style.display = 'none' diff --git a/assets/js/socket.js b/assets/js/socket.js index 2263d64..2bb3600 100644 --- a/assets/js/socket.js +++ b/assets/js/socket.js @@ -82,6 +82,8 @@ export class SocketManager { break case 'updateServers': { + let requestGraphRedraw = false + for (let serverId = 0; serverId < payload.updates.length; serverId++) { // The backend may send "update" events prior to receiving all "add" events // A server has only been added once it's ServerRegistration is defined @@ -105,10 +107,19 @@ export class SocketManager { // Only redraw the graph if not mutating hidden data if (serverRegistration.isVisible) { - this._app.graphDisplayManager.requestRedraw() + requestGraphRedraw = true } } } + + // Run redraw tasks after handling bulk updates + if (requestGraphRedraw) { + this._app.graphDisplayManager.redraw() + } + + this._app.percentageBar.redraw() + this._app.updateGlobalStats() + break }