mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-07 22:45:46 +01:00
faster notif prune
This commit is contained in:
@@ -285,11 +285,21 @@ var async = require('async'),
|
||||
return winston.error(err.message);
|
||||
}
|
||||
|
||||
async.filter(nids, function(nid, next) {
|
||||
db.getObjectField('notifications:' + nid, 'datetime', function(err, datetime) {
|
||||
next(!err && parseInt(datetime, 10) < cutoffTime);
|
||||
var keys = nids.map(function(nid) {
|
||||
return 'notifications:' + nid;
|
||||
});
|
||||
}, function(expiredNids) {
|
||||
|
||||
db.getObjectsFields(keys, ['nid', 'datetime'], function(err, notifs) {
|
||||
if (err) {
|
||||
return winston.error(err.message);
|
||||
}
|
||||
|
||||
var expiredNids = notifs.filter(function(notif) {
|
||||
return notif && parseInt(notif.datetime, 10) < cutoffTime;
|
||||
}).map(function(notif) {
|
||||
return notif.nid;
|
||||
});
|
||||
|
||||
async.each(expiredNids, function(nid, next) {
|
||||
async.parallel([
|
||||
function(next) {
|
||||
@@ -303,15 +313,15 @@ var async = require('async'),
|
||||
next(err);
|
||||
});
|
||||
}, function(err) {
|
||||
if (!err) {
|
||||
if (err) {
|
||||
return winston.error('Encountered error pruning notifications: ' + err.message);
|
||||
}
|
||||
|
||||
if (process.env.NODE_ENV === 'development') {
|
||||
winston.info('[notifications.prune] Notification pruning completed. ' + numPruned + ' expired notification' + (numPruned !== 1 ? 's' : '') + ' removed.');
|
||||
}
|
||||
var diff = process.hrtime(start);
|
||||
events.log('Pruning notifications took : ' + (diff[0] * 1e3 + diff[1] / 1e6) + ' ms');
|
||||
} else {
|
||||
winston.error('Encountered error pruning notifications: ' + err.message);
|
||||
}
|
||||
events.log('Pruning '+ numPruned + 'notifications took : ' + (diff[0] * 1e3 + diff[1] / 1e6) + ' ms');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user