Skip to content

Node.js based forum software built for the modern web

closes #2264

barisusaklif463030e7656
diff --git a/src/categories/recentreplies.js b/src/categories/recentreplies.js
index d1135f7a1c..7d9cbcc047 100644
--- a/src/categories/recentreplies.js
+++ b/src/categories/recentreplies.js
@@ -113,31 +113,50 @@ module.exports = function(Categories) {
return;
}
- var keys = pids.map(function(pid) {
- return 'post:' + pid;
- });
-
- db.getObjectsFields(keys, ['timestamp'], function(err, postData) {
- if (err) {
- return winston.error(err.message);
+ var start = 0,
+ done = false,
+ batch = 50;
+
+ async.whilst(function() {
+ return !done;
+ }, function(next) {
+ var movePids = pids.slice(start, start + batch);
+ if (!movePids.length) {
+ done = true;
+ return next();
}
-
- var timestamps = postData.map(function(post) {
- return post && post.timestamp;
+ var keys = movePids.map(function(pid) {
+ return 'post:' + pid;
});
- async.parallel([
- function(next) {
- db.sortedSetRemove('categories:recent_posts:cid:' + oldCid, pids, next);
- },
- function(next) {
- db.sortedSetAdd('categories:recent_posts:cid:' + cid, timestamps, pids, next);
- }
- ], function(err) {
+ db.getObjectsFields(keys, ['timestamp'], function(err, postData) {
if (err) {
- winston.error(err.message);
+ return next(err);
}
+
+ var timestamps = postData.map(function(post) {
+ return post && post.timestamp;
+ });
+
+ async.parallel([
+ function(next) {
+ db.sortedSetRemove('categories:recent_posts:cid:' + oldCid, movePids, next);
+ },
+ function(next) {
+ db.sortedSetAdd('categories:recent_posts:cid:' + cid, timestamps, movePids, next);
+ }
+ ], function(err) {
+ if (err) {
+ return next(err);
+ }
+ start += batch;
+ next();
+ });
});
+ }, function(err) {
+ if (err) {
+ winston.error(err.stack);
+ }
});
});
};