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