Skip to content

Commit

Permalink
Merge pull request thedjpetersen#144 from ericbarch/master
Browse files Browse the repository at this point in the history
Backend setting for max log size
  • Loading branch information
ericbarch committed Jul 15, 2012
2 parents 823e53e + da1dcc3 commit 1de4bcc
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
4 changes: 4 additions & 0 deletions config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,7 @@ exports.prod = {
client_port: 80, // Websockets talk on port 80 on Nodester, regardless of listen port
mongoose_auth: 'mongodb://mongodb@localhost/subway'
}

exports.misc = {
max_log_size: 32000
}
19 changes: 18 additions & 1 deletion lib/irclink.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
var irc = require('irc'),
mongoose = require('mongoose');
mongoose = require('mongoose'),
config = require('../config');

// establish models
var User = mongoose.model('User');
Expand Down Expand Up @@ -160,6 +161,22 @@ IRCLink.prototype = {
if (this.username) {
var message = new Message({channel: target.toLowerCase(), server: this.server.toLowerCase(), linkedto: this.username, user: from, message: msg});
message.save();

// keep log size in check
Message.count({}, function(err, count) {
if (count > config.misc.max_log_size) {
var query = Message.find({});

query.limit(count - config.misc.max_log_size);
query.sort('date', 1);

query.exec(function (err, records) {
records.forEach(function(record){
record.remove();
});
});
}
});
}
}
};
Expand Down

0 comments on commit 1de4bcc

Please sign in to comment.