From f6e2a1981d4c552368cd06ccf5dc400db298c2d6 Mon Sep 17 00:00:00 2001 From: Alexander Akait <4567934+alexander-akait@users.noreply.github.com> Date: Mon, 4 Oct 2021 12:20:22 +0300 Subject: [PATCH] fix: perf (#3906) --- lib/Server.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/Server.js b/lib/Server.js index eaf879bee3..43e9896fa3 100644 --- a/lib/Server.js +++ b/lib/Server.js @@ -36,13 +36,13 @@ class Server { this.webSocketProxies = []; this.sockets = []; this.compiler = compiler; + this.currentHash = null; } static get DEFAULT_STATS() { return { all: false, hash: true, - assets: true, warnings: true, errors: true, errorDetails: false, @@ -1970,13 +1970,13 @@ class Server { // eslint-disable-next-line class-methods-use-this sendMessage(clients, type, data) { - clients.forEach((client) => { + for (const client of clients) { // `sockjs` uses `1` to indicate client is ready to accept data // `ws` uses `WebSocket.OPEN`, but it is mean `1` too if (client.readyState === 1) { client.send(JSON.stringify({ type, data })); } - }); + } } serveMagicHtml(req, res, next) { @@ -2011,8 +2011,7 @@ class Server { stats && (!stats.errors || stats.errors.length === 0) && (!stats.warnings || stats.warnings.length === 0) && - stats.assets && - stats.assets.every((asset) => !asset.emitted); + this.currentHash === stats.hash; if (shouldEmit) { this.sendMessage(clients, "still-ok"); @@ -2020,6 +2019,7 @@ class Server { return; } + this.currentHash = stats.hash; this.sendMessage(clients, "hash", stats.hash); if (stats.errors.length > 0 || stats.warnings.length > 0) {