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.
This commit is contained in:
Maxime Poulin 2016-04-03 15:43:11 -04:00
parent 9d59bd53b9
commit 7209bcd58a
2 changed files with 19 additions and 0 deletions

View File

@ -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.
//

View File

@ -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