err check, assignPostsToCategory is sync

v1.18.x
barisusakli 10 years ago
parent af4cbfb20d
commit 7823416410

@ -29,6 +29,9 @@ module.exports = function(Categories) {
return callback(null, []); return callback(null, []);
} }
async.map(categoryData, getRecentTopicPids, function(err, results) { async.map(categoryData, getRecentTopicPids, function(err, results) {
if (err) {
return callback(err);
}
var pids = _.flatten(results); var pids = _.flatten(results);
@ -41,21 +44,21 @@ module.exports = function(Categories) {
return callback(err); return callback(err);
} }
async.each(categoryData, function(category, next) { categoryData.forEach(function(category) {
assignPostsToCategory(category, posts, next); assignPostsToCategory(category, posts);
}, callback); });
callback();
}); });
}); });
}; };
function assignPostsToCategory(category, posts, next) { function assignPostsToCategory(category, posts) {
category.posts = posts.filter(function(post) { category.posts = posts.filter(function(post) {
return parseInt(post.category.cid, 10) === parseInt(category.cid, 10); return parseInt(post.category.cid, 10) === parseInt(category.cid, 10);
}).sort(function(a, b) { }).sort(function(a, b) {
return b.timestamp - a.timestamp; return b.timestamp - a.timestamp;
}).slice(0, parseInt(category.numRecentReplies, 10)); }).slice(0, parseInt(category.numRecentReplies, 10));
next();
} }
function getRecentTopicPids(category, callback) { function getRecentTopicPids(category, callback) {

Loading…
Cancel
Save