mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-17 03:01:08 +01:00
err check, assignPostsToCategory is sync
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user