|
|
|
@ -212,70 +212,40 @@ var async = require('async'),
|
|
|
|
|
|
|
|
|
|
var cutoffTime = cutoff.getTime();
|
|
|
|
|
|
|
|
|
|
async.parallel({
|
|
|
|
|
"inboxes": function(next) {
|
|
|
|
|
db.getSortedSetRange('users:joindate', 0, -1, function(err, uids) {
|
|
|
|
|
if(err) {
|
|
|
|
|
return next(err);
|
|
|
|
|
db.getSetMembers('notifications', function(err, nids) {
|
|
|
|
|
async.filter(nids, function(nid, next) {
|
|
|
|
|
db.getObjectField('notifications:' + nid, 'datetime', function(err, datetime) {
|
|
|
|
|
if (parseInt(datetime, 10) < cutoffTime) {
|
|
|
|
|
next(true);
|
|
|
|
|
} else {
|
|
|
|
|
next(false);
|
|
|
|
|
}
|
|
|
|
|
uids = uids.map(function(uid) {
|
|
|
|
|
return 'uid:' + uid + ':notifications:unread';
|
|
|
|
|
});
|
|
|
|
|
next(null, uids);
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
"expiredNids": function(next) {
|
|
|
|
|
db.getSetMembers('notifications', function(err, nids) {
|
|
|
|
|
async.filter(nids, function(nid, next) {
|
|
|
|
|
db.getObjectField('notifications:' + nid, 'datetime', function(err, datetime) {
|
|
|
|
|
if (parseInt(datetime, 10) < cutoffTime) {
|
|
|
|
|
next(true);
|
|
|
|
|
} else {
|
|
|
|
|
next(false);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}, function(expiredNids) {
|
|
|
|
|
next(null, expiredNids);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}, function(err, results) {
|
|
|
|
|
if(err) {
|
|
|
|
|
if (process.env.NODE_ENV === 'development') {
|
|
|
|
|
winston.error('[notifications.prune] Ran into trouble pruning expired notifications. Stack trace to follow.');
|
|
|
|
|
winston.error(err.stack);
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async.eachSeries(results.expiredNids, function(nid, next) {
|
|
|
|
|
|
|
|
|
|
db.sortedSetsScore(results.inboxes, nid, function(err, results) {
|
|
|
|
|
if(err) {
|
|
|
|
|
return next(err);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// If the notification is not present in any inbox, delete it altogether
|
|
|
|
|
var expired = results.every(function(present) {
|
|
|
|
|
return present === null;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (expired) {
|
|
|
|
|
destroy(nid);
|
|
|
|
|
}, function(expiredNids) {
|
|
|
|
|
async.each(expiredNids, function(nid, next) {
|
|
|
|
|
async.parallel([
|
|
|
|
|
function(next) {
|
|
|
|
|
db.setRemove('notifications', nid, next)
|
|
|
|
|
},
|
|
|
|
|
function(next) {
|
|
|
|
|
db.delete('notifications:' + nid, next)
|
|
|
|
|
}
|
|
|
|
|
], function(err) {
|
|
|
|
|
numPruned++;
|
|
|
|
|
next(err);
|
|
|
|
|
});
|
|
|
|
|
}, function(err) {
|
|
|
|
|
if (!err) {
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
next();
|
|
|
|
|
});
|
|
|
|
|
}, function(err) {
|
|
|
|
|
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');
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|