mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-07 06:25:50 +01:00
removed 2x calls to getRecentTopicReplies
This commit is contained in:
@@ -121,34 +121,31 @@ categoriesController.list = function(req, res, next) {
|
||||
},
|
||||
categories: function (next) {
|
||||
var uid = req.user ? req.user.uid : 0;
|
||||
categories.getCategoriesByPrivilege(uid, 'find', function (err, categoryData) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
var childCategories = [];
|
||||
|
||||
for(var i=categoryData.length - 1; i>=0; --i) {
|
||||
|
||||
if (Array.isArray(categoryData[i].children) && categoryData[i].children.length) {
|
||||
childCategories.push.apply(childCategories, categoryData[i].children);
|
||||
}
|
||||
|
||||
if (categoryData[i].parent && categoryData[i].parent.cid) {
|
||||
categoryData.splice(i, 1);
|
||||
}
|
||||
}
|
||||
|
||||
async.parallel([
|
||||
var categoryData;
|
||||
async.waterfall([
|
||||
function(next) {
|
||||
categories.getRecentTopicReplies(categoryData, uid, next);
|
||||
categories.getCategoriesByPrivilege(uid, 'find', next);
|
||||
},
|
||||
function(next) {
|
||||
categories.getRecentTopicReplies(childCategories, uid, next);
|
||||
function(_categoryData, next) {
|
||||
categoryData = _categoryData;
|
||||
var allCategories = [];
|
||||
|
||||
categoryData = categoryData.filter(function(category) {
|
||||
if (!category.parent) {
|
||||
allCategories.push(category);
|
||||
}
|
||||
|
||||
if (Array.isArray(category.children) && category.children.length) {
|
||||
allCategories.push.apply(allCategories, category.children);
|
||||
}
|
||||
return category && !category.parent;
|
||||
});
|
||||
|
||||
categories.getRecentTopicReplies(allCategories, uid, next);
|
||||
}
|
||||
], function(err) {
|
||||
next(err, categoryData);
|
||||
});
|
||||
});
|
||||
}
|
||||
}, function (err, data) {
|
||||
if (err) {
|
||||
|
||||
Reference in New Issue
Block a user