From: Jack Allnutt Date: Tue, 13 Aug 2013 22:32:30 +0000 (+0100) Subject: Batch clients into sets of 100 for reconfig command X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=7d1ad2df4c392a0babf00e7c3dd5fa8c18e542ec;p=KiwiIRC.git Batch clients into sets of 100 for reconfig command --- diff --git a/server/client.js b/server/client.js index 2634cbb..3caef07 100755 --- a/server/client.js +++ b/server/client.js @@ -45,6 +45,8 @@ var Client = function (websocket) { websocket.on('error', function () { websocketError.apply(that, arguments); }); + + this.disposed = false; }; util.inherits(Client, events.EventEmitter); @@ -67,6 +69,7 @@ Client.prototype.sendKiwiCommand = function (command, data, callback) { }; Client.prototype.dispose = function () { + this.disposed = true; this.emit('dispose'); this.removeAllListeners(); }; diff --git a/server/kiwi.js b/server/kiwi.js index 26d5b9c..12e5106 100755 --- a/server/kiwi.js +++ b/server/kiwi.js @@ -147,9 +147,28 @@ global.servers = { config.on('loaded', function () { + var clients = []; for (var client in global.clients.clients) { - global.clients.clients[client].sendKiwiCommand('reconfig'); + clients.push(global.clients.clients[client]); } + var sendReconfigCommand = function (list) { + var cutoff; + if (list.length >= 100) { + setTimeout(function () { + sendReconfigCommand(list.slice(100)); + }, 200); + cutoff = 100; + } else { + cutoff = list.length; + } + list.slice(0, cutoff).forEach(function (client) { + if (!client.disposed) { + client.sendKiwiCommand('reconfig'); + } + }); + }; + + sendReconfigCommand(clients); });