Skip to content

Node.js based forum software built for the modern web

fixing notifications.prune

Baris Usakli806a454b056e
diff --git a/src/database/mongo.js b/src/database/mongo.js
index c90f6bc3cf..a9e17b8e02 100644
--- a/src/database/mongo.js
+++ b/src/database/mongo.js
@@ -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) {
diff --git a/src/database/redis.js b/src/database/redis.js
index ca7f3483f2..b2a17845ce 100644
--- a/src/database/redis.js
+++ b/src/database/redis.js
@@ -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);
diff --git a/src/notifications.js b/src/notifications.js
index b05c38a0ef..47cf782368 100644
--- a/src/notifications.js
+++ b/src/notifications.js
@@ -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();
+ 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;
+ }
- for(x=0;x<numInboxes;x++) {
- multi.zscore(results.inboxes[x], nid);
- }
+ var numInboxes = results.inboxes.length,
+ x;
+ console.log(results.inboxes, results.expiredNids);
+ async.eachSeries(results.expiredNids, function(nid, next) {
+ var multi = RDB.multi();
- 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;
- }
- });
+ for(x=0; x<numInboxes; ++x) {
+ multi.zscore(results.inboxes[x], nid);
+ }
- if (expired) {
- destroy(nid);
- numPruned++;
- }
+ 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;
+ }
+ });
- next();
- });
- }, function(err) {
- if (process.env.NODE_ENV === 'development') {
- winston.info('[notifications.prune] Notification pruning completed. ' + numPruned + ' expired notification' + (numPruned !== 1 ? 's' : '') + ' removed.');
+ if (expired) {
+ destroy(nid);
+ numPruned++;
}
+
+ next();
});
- } else {
+ }, function(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);
+ winston.info('[notifications.prune] Notification pruning completed. ' + numPruned + ' expired notification' + (numPruned !== 1 ? 's' : '') + ' removed.');
}
- }
+ });
+
});
};
diff --git a/src/routes/debug.js b/src/routes/debug.js
index dd1f147229..5228ed4339 100644
--- a/src/routes/debug.js
+++ b/src/routes/debug.js
@@ -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');