mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-07 06:25:50 +01:00
first pass, #999
This commit is contained in:
@@ -212,19 +212,6 @@ var async = require('async'),
|
|||||||
|
|
||||||
var cutoffTime = cutoff.getTime();
|
var cutoffTime = cutoff.getTime();
|
||||||
|
|
||||||
async.parallel({
|
|
||||||
"inboxes": function(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);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
"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) {
|
||||||
@@ -235,47 +222,30 @@ var async = require('async'),
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}, function(expiredNids) {
|
}, function(expiredNids) {
|
||||||
next(null, 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, results) {
|
], function(err) {
|
||||||
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);
|
|
||||||
numPruned++;
|
numPruned++;
|
||||||
}
|
next(err);
|
||||||
|
|
||||||
next();
|
|
||||||
});
|
});
|
||||||
}, function(err) {
|
}, function(err) {
|
||||||
|
if (!err) {
|
||||||
if (process.env.NODE_ENV === 'development') {
|
if (process.env.NODE_ENV === 'development') {
|
||||||
winston.info('[notifications.prune] Notification pruning completed. ' + numPruned + ' expired notification' + (numPruned !== 1 ? 's' : '') + ' removed.');
|
winston.info('[notifications.prune] Notification pruning completed. ' + numPruned + ' expired notification' + (numPruned !== 1 ? 's' : '') + ' removed.');
|
||||||
}
|
}
|
||||||
var diff = process.hrtime(start);
|
var diff = process.hrtime(start);
|
||||||
events.log('Pruning notifications took : ' + (diff[0] * 1e3 + diff[1] / 1e6) + ' ms');
|
events.log('Pruning notifications took : ' + (diff[0] * 1e3 + diff[1] / 1e6) + ' ms');
|
||||||
|
} else {
|
||||||
|
winston.error('Encountered error pruning notifications: ' + err.message);
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user