From 40fff367d18fdb8629802eb9874cedd3d79719ae Mon Sep 17 00:00:00 2001 From: barisusakli Date: Tue, 16 Sep 2014 23:28:04 -0400 Subject: [PATCH] faster topic move --- src/categories/recentreplies.js | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/categories/recentreplies.js b/src/categories/recentreplies.js index a215a764d5..7365956219 100644 --- a/src/categories/recentreplies.js +++ b/src/categories/recentreplies.js @@ -103,24 +103,13 @@ module.exports = function(Categories) { Categories.moveRecentReplies = function(tid, oldCid, cid) { - function movePost(postData, next) { - async.parallel([ - function(next) { - db.sortedSetRemove('categories:recent_posts:cid:' + oldCid, postData.pid, next); - }, - function(next) { - db.sortedSetAdd('categories:recent_posts:cid:' + cid, postData.timestamp, postData.pid, next); - } - ], next); - } - updatePostCount(tid, oldCid, cid); topics.getPids(tid, function(err, pids) { if (err) { return winston.error(err.message); } - if (pids && !pids.length) { + if (!Array.isArray(pids) || !pids.length) { return; } @@ -128,12 +117,23 @@ module.exports = function(Categories) { return 'post:' + pid; }); - db.getObjectsFields(keys, ['pid', 'timestamp'], function(err, postData) { + db.getObjectsFields(keys, ['timestamp'], function(err, postData) { if (err) { return winston.error(err.message); } - async.each(postData, movePost, function(err) { + var timestamps = postData.map(function(post) { + return post && post.timestamp; + }); + + 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) { if (err) { winston.error(err.message); }