Skip to content

Node.js based forum software built for the modern web

make 1 call for parentCids

Barış Soner Uşaklıd5af39ca5df8
diff --git a/src/categories/data.js b/src/categories/data.js
index 96ed3214a5..d252953eef 100644
--- a/src/categories/data.js
+++ b/src/categories/data.js
@@ -16,10 +16,9 @@ module.exports = function (Categories) {
return setImmediate(callback, null, []);
}
- var keys = cids.map(cid => 'category:' + cid);
-
async.waterfall([
function (next) {
+ const keys = cids.map(cid => 'category:' + cid);
if (fields.length) {
db.getObjectsFields(keys, fields, next);
} else {
diff --git a/src/categories/index.js b/src/categories/index.js
index efb3cbad70..eebbebe541 100644
--- a/src/categories/index.js
+++ b/src/categories/index.js
@@ -235,19 +235,21 @@ Categories.getParentsAndChildren = function (categoryData, uid, callback) {
};
Categories.getChildren = function (cids, uid, callback) {
- var categories = cids.map(cid => ({ cid: cid }));
-
- async.each(categories, function (category, next) {
- Categories.getCategoryField(category.cid, 'parentCid', function (err, parentCid) {
- if (err) {
- return next(err);
- }
- category.parentCid = parentCid;
- getChildrenRecursive(category, uid, next);
- });
- }, function (err) {
- callback(err, categories.map(c => c && c.children));
- });
+ var categories;
+ async.waterfall([
+ function (next) {
+ Categories.getCategoriesFields(cids, ['parentCid'], next);
+ },
+ function (categoryData, next) {
+ categories = categoryData.map((category, index) => ({ cid: cids[index], parentCid: category.parentCid }));
+ async.each(categories, function (category, next) {
+ getChildrenRecursive(category, uid, next);
+ }, next);
+ },
+ function (next) {
+ next(null, categories.map(c => c && c.children));
+ },
+ ], callback);
};
function getChildrenRecursive(category, uid, callback) {