From 7209bcd58acb40c7e83c2ad8ae06fcef1fe20e39 Mon Sep 17 00:00:00 2001 From: Maxime Poulin Date: Sun, 3 Apr 2016 15:43:11 -0400 Subject: [PATCH] Add config option to limit in-memory history size This adds a (temporary?) config option to limit the amount of messages stored per channel to avoid the server's memory usage to grow as channels fills up with messages. --- defaults/config.js | 11 +++++++++++ src/plugins/irc-events/message.js | 8 ++++++++ 2 files changed, 19 insertions(+) diff --git a/defaults/config.js b/defaults/config.js index 5d04c2b7..f57b40c7 100644 --- a/defaults/config.js +++ b/defaults/config.js @@ -124,6 +124,17 @@ module.exports = { timezone: "UTC+00:00" }, + // + // Maximum number of history lines per channel + // + // Defines the maximum number of history lines that will be kept in + // memory per channel/query, in order to reduce the memory usage of + // the server. Negative means unlimited. + // + // @type integer + // @default -1 + maxHistory: -1, + // // Default values for the 'Connect' form. // diff --git a/src/plugins/irc-events/message.js b/src/plugins/irc-events/message.js index bc693211..0894843b 100644 --- a/src/plugins/irc-events/message.js +++ b/src/plugins/irc-events/message.js @@ -1,9 +1,12 @@ var _ = require("lodash"); var Chan = require("../../models/chan"); var Msg = require("../../models/msg"); +var Helper = require("../../helper"); module.exports = function(irc, network) { var client = this; + var config = Helper.getConfig(); + irc.on("message", function(data) { if (data.message.indexOf("\u0001") === 0 && data.message.substring(0, 7) !== "\u0001ACTION") { // Hide ctcp messages. @@ -62,6 +65,11 @@ module.exports = function(irc, network) { highlight: highlight }); chan.messages.push(msg); + + if (config.maxHistory >= 0 && chan.messages.length > config.maxHistory) { + chan.messages.splice(0, chan.messages.length - config.maxHistory); + } + client.emit("msg", { chan: chan.id, msg: msg