Merge pull request #243 from maxpoulin64/limithistory

Add config option to limit in-memory history size
This commit is contained in:
Alistair McKinlay 2016-04-06 08:49:35 +01:00
commit ab95419c89
2 changed files with 19 additions and 0 deletions

View File

@ -124,6 +124,17 @@ module.exports = {
timezone: "UTC+00:00" 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. // Default values for the 'Connect' form.
// //

View File

@ -1,9 +1,12 @@
var _ = require("lodash"); var _ = require("lodash");
var Chan = require("../../models/chan"); var Chan = require("../../models/chan");
var Msg = require("../../models/msg"); var Msg = require("../../models/msg");
var Helper = require("../../helper");
module.exports = function(irc, network) { module.exports = function(irc, network) {
var client = this; var client = this;
var config = Helper.getConfig();
irc.on("message", function(data) { irc.on("message", function(data) {
if (data.message.indexOf("\u0001") === 0 && data.message.substring(0, 7) !== "\u0001ACTION") { if (data.message.indexOf("\u0001") === 0 && data.message.substring(0, 7) !== "\u0001ACTION") {
// Hide ctcp messages. // Hide ctcp messages.
@ -62,6 +65,11 @@ module.exports = function(irc, network) {
highlight: highlight highlight: highlight
}); });
chan.messages.push(msg); 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", { client.emit("msg", {
chan: chan.id, chan: chan.id,
msg: msg msg: msg