Backend setting for max log size #144

Merged
merged 1 commit into from Jul 15, 2012
+22 −1
Split
View
@@ -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
+}
View
@@ -1,5 +1,6 @@
var irc = require('irc'),
- mongoose = require('mongoose');
+ mongoose = require('mongoose'),
+ config = require('../config');
// establish models
var User = mongoose.model('User');
@@ -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();
+ });
+ });
+ }
+ });
}
}
};