fixing notifications.prune

v1.18.x
Baris Usakli 11 years ago
parent 705754e823
commit 806a454b05

@ -20,7 +20,6 @@
process.exit(); process.exit();
} }
// TODO: fill out settings.db
module.sessionStore = new mongoStore({ module.sessionStore = new mongoStore({
db: db db: db
}); });
@ -477,6 +476,14 @@
}); });
} }
module.sortedSetScore = function(key, value, callback) {
throw new Error('not-implemented');
}
module.sortedSetsScore = function(keys, value, callback) {
throw new Error('not-implemented');
}
// lists // lists
module.listPrepend = function(key, value, callback) { module.listPrepend = function(key, value, callback) {
module.isObjectField(key, 'array', function(err, exists) { module.isObjectField(key, 'array', function(err, exists) {

@ -311,6 +311,20 @@
redisClient.zrank(key, value, callback); redisClient.zrank(key, value, callback);
} }
module.sortedSetScore = function(key, value, callback) {
redisClient.zscore(key, value, callback);
}
module.sortedSetsScore = function(keys, value, callback) {
var multi = redisClient.multi();
for(x=0; x<keys.length; ++x) {
multi.zscore(keys[x], value);
}
multi.exec(callback);
}
// lists // lists
module.listPrepend = function(key, value, callback) { module.listPrepend = function(key, value, callback) {
redisClient.lpush(key, value, callback); redisClient.lpush(key, value, callback);

@ -211,9 +211,18 @@ var async = require('async'),
async.parallel({ async.parallel({
"inboxes": function(next) { "inboxes": function(next) {
RDB.keys('uid:*:notifications:unread', next); //RDB.keys('uid:*:notifications:unread', next);
db.getSortedSetRange('users:joindate', 0, -1, function(err, uids) {
if(err) {
return next(err);
}
uids = uids.map(function(uid) {
return 'uid:' + uid + ':notifications:unread';
});
next(null, uids);
});
}, },
"nids": function(next) { "expiredNids": function(next) {
db.getSetMembers('notifications', function(err, nids) { db.getSetMembers('notifications', function(err, nids) {
async.filter(nids, function(nid, next) { async.filter(nids, function(nid, next) {
db.getObjectField('notifications:' + nid, 'datetime', function(err, datetime) { db.getObjectField('notifications:' + nid, 'datetime', function(err, datetime) {
@ -229,43 +238,45 @@ var async = require('async'),
}); });
} }
}, function(err, results) { }, function(err, results) {
if (!err) { if(err) {
var numInboxes = results.inboxes.length, if (process.env.NODE_ENV === 'development') {
x; winston.error('[notifications.prune] Ran into trouble pruning expired notifications. Stack trace to follow.');
winston.error(err.stack);
async.eachSeries(results.nids, function(nid, next) { }
var multi = RDB.multi(); return;
}
for(x=0;x<numInboxes;x++) { var numInboxes = results.inboxes.length,
multi.zscore(results.inboxes[x], nid); x;
} console.log(results.inboxes, results.expiredNids);
async.eachSeries(results.expiredNids, function(nid, next) {
var multi = RDB.multi();
multi.exec(function(err, results) { for(x=0; x<numInboxes; ++x) {
// If the notification is not present in any inbox, delete it altogether multi.zscore(results.inboxes[x], nid);
var expired = results.every(function(present) { }
if (present === null) {
return true;
}
});
if (expired) { multi.exec(function(err, results) {
destroy(nid); // If the notification is not present in any inbox, delete it altogether
numPruned++; var expired = results.every(function(present) {
} if (present === null) {
return true;
}
});
next(); if (expired) {
}); destroy(nid);
}, function(err) { numPruned++;
if (process.env.NODE_ENV === 'development') {
winston.info('[notifications.prune] Notification pruning completed. ' + numPruned + ' expired notification' + (numPruned !== 1 ? 's' : '') + ' removed.');
} }
next();
}); });
} else { }, function(err) {
if (process.env.NODE_ENV === 'development') { if (process.env.NODE_ENV === 'development') {
winston.error('[notifications.prune] Ran into trouble pruning expired notifications. Stack trace to follow.'); winston.info('[notifications.prune] Notification pruning completed. ' + numPruned + ' expired notification' + (numPruned !== 1 ? 's' : '') + ' removed.');
winston.error(err.stack);
} }
} });
}); });
}; };

@ -79,6 +79,18 @@ var DebugRoute = function(app) {
}); });
}); });
app.get('/prune', function(req, res) {
require('./../notifications').prune();
//function(err, result) {
// if(err) {
// res.send(err.message);
// return;
// }
res.send('done');
//}
});
app.get('/mongo', function(req, res) { app.get('/mongo', function(req, res) {
var db = require('./../database'); var db = require('./../database');

Loading…
Cancel
Save