mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-02 12:05:57 +01:00
fixing notifications.prune
This commit is contained in:
@@ -20,7 +20,6 @@
|
||||
process.exit();
|
||||
}
|
||||
|
||||
// TODO: fill out settings.db
|
||||
module.sessionStore = new mongoStore({
|
||||
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
|
||||
module.listPrepend = function(key, value, callback) {
|
||||
module.isObjectField(key, 'array', function(err, exists) {
|
||||
|
||||
@@ -311,6 +311,20 @@
|
||||
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
|
||||
module.listPrepend = function(key, value, callback) {
|
||||
redisClient.lpush(key, value, callback);
|
||||
|
||||
@@ -211,9 +211,18 @@ var async = require('async'),
|
||||
|
||||
async.parallel({
|
||||
"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) {
|
||||
async.filter(nids, function(nid, next) {
|
||||
db.getObjectField('notifications:' + nid, 'datetime', function(err, datetime) {
|
||||
@@ -229,43 +238,45 @@ var async = require('async'),
|
||||
});
|
||||
}
|
||||
}, function(err, results) {
|
||||
if (!err) {
|
||||
var numInboxes = results.inboxes.length,
|
||||
x;
|
||||
|
||||
async.eachSeries(results.nids, function(nid, next) {
|
||||
var multi = RDB.multi();
|
||||
|
||||
for(x=0;x<numInboxes;x++) {
|
||||
multi.zscore(results.inboxes[x], nid);
|
||||
}
|
||||
|
||||
multi.exec(function(err, results) {
|
||||
// If the notification is not present in any inbox, delete it altogether
|
||||
var expired = results.every(function(present) {
|
||||
if (present === null) {
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
if (expired) {
|
||||
destroy(nid);
|
||||
numPruned++;
|
||||
}
|
||||
|
||||
next();
|
||||
});
|
||||
}, function(err) {
|
||||
if (process.env.NODE_ENV === 'development') {
|
||||
winston.info('[notifications.prune] Notification pruning completed. ' + numPruned + ' expired notification' + (numPruned !== 1 ? 's' : '') + ' removed.');
|
||||
}
|
||||
});
|
||||
} else {
|
||||
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;
|
||||
}
|
||||
|
||||
var numInboxes = results.inboxes.length,
|
||||
x;
|
||||
console.log(results.inboxes, results.expiredNids);
|
||||
async.eachSeries(results.expiredNids, function(nid, next) {
|
||||
var multi = RDB.multi();
|
||||
|
||||
for(x=0; x<numInboxes; ++x) {
|
||||
multi.zscore(results.inboxes[x], nid);
|
||||
}
|
||||
|
||||
multi.exec(function(err, results) {
|
||||
// If the notification is not present in any inbox, delete it altogether
|
||||
var expired = results.every(function(present) {
|
||||
if (present === null) {
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
if (expired) {
|
||||
destroy(nid);
|
||||
numPruned++;
|
||||
}
|
||||
|
||||
next();
|
||||
});
|
||||
}, function(err) {
|
||||
if (process.env.NODE_ENV === 'development') {
|
||||
winston.info('[notifications.prune] Notification pruning completed. ' + numPruned + ' expired notification' + (numPruned !== 1 ? 's' : '') + ' removed.');
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -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) {
|
||||
|
||||
var db = require('./../database');
|
||||
|
||||
Reference in New Issue
Block a user