From 7823416410cb948594eb9efd5646f877beb7da74 Mon Sep 17 00:00:00 2001 From: barisusakli Date: Sat, 8 Nov 2014 23:22:10 -0500 Subject: [PATCH] err check, assignPostsToCategory is sync --- src/categories/recentreplies.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/categories/recentreplies.js b/src/categories/recentreplies.js index 38d2c74590..9c076fbcfc 100644 --- a/src/categories/recentreplies.js +++ b/src/categories/recentreplies.js @@ -29,6 +29,9 @@ module.exports = function(Categories) { return callback(null, []); } async.map(categoryData, getRecentTopicPids, function(err, results) { + if (err) { + return callback(err); + } var pids = _.flatten(results); @@ -41,21 +44,21 @@ module.exports = function(Categories) { return callback(err); } - async.each(categoryData, function(category, next) { - assignPostsToCategory(category, posts, next); - }, callback); + categoryData.forEach(function(category) { + assignPostsToCategory(category, posts); + }); + + callback(); }); }); }; - function assignPostsToCategory(category, posts, next) { + function assignPostsToCategory(category, posts) { category.posts = posts.filter(function(post) { return parseInt(post.category.cid, 10) === parseInt(category.cid, 10); }).sort(function(a, b) { return b.timestamp - a.timestamp; }).slice(0, parseInt(category.numRecentReplies, 10)); - - next(); } function getRecentTopicPids(category, callback) {