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:
parent
9d59bd53b9
commit
7209bcd58a
@ -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.
|
||||||
//
|
//
|
||||||
|
@ -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
|
||||||
|
Loading…
Reference in New Issue
Block a user