mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-07 14:35:47 +01:00
make 1 call for parentCids
This commit is contained in:
@@ -16,10 +16,9 @@ module.exports = function (Categories) {
|
|||||||
return setImmediate(callback, null, []);
|
return setImmediate(callback, null, []);
|
||||||
}
|
}
|
||||||
|
|
||||||
var keys = cids.map(cid => 'category:' + cid);
|
|
||||||
|
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
function (next) {
|
function (next) {
|
||||||
|
const keys = cids.map(cid => 'category:' + cid);
|
||||||
if (fields.length) {
|
if (fields.length) {
|
||||||
db.getObjectsFields(keys, fields, next);
|
db.getObjectsFields(keys, fields, next);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -235,19 +235,21 @@ Categories.getParentsAndChildren = function (categoryData, uid, callback) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Categories.getChildren = function (cids, uid, callback) {
|
Categories.getChildren = function (cids, uid, callback) {
|
||||||
var categories = cids.map(cid => ({ cid: cid }));
|
var categories;
|
||||||
|
async.waterfall([
|
||||||
async.each(categories, function (category, next) {
|
function (next) {
|
||||||
Categories.getCategoryField(category.cid, 'parentCid', function (err, parentCid) {
|
Categories.getCategoriesFields(cids, ['parentCid'], next);
|
||||||
if (err) {
|
},
|
||||||
return next(err);
|
function (categoryData, next) {
|
||||||
}
|
categories = categoryData.map((category, index) => ({ cid: cids[index], parentCid: category.parentCid }));
|
||||||
category.parentCid = parentCid;
|
async.each(categories, function (category, next) {
|
||||||
getChildrenRecursive(category, uid, next);
|
getChildrenRecursive(category, uid, next);
|
||||||
});
|
}, next);
|
||||||
}, function (err) {
|
},
|
||||||
callback(err, categories.map(c => c && c.children));
|
function (next) {
|
||||||
});
|
next(null, categories.map(c => c && c.children));
|
||||||
|
},
|
||||||
|
], callback);
|
||||||
};
|
};
|
||||||
|
|
||||||
function getChildrenRecursive(category, uid, callback) {
|
function getChildrenRecursive(category, uid, callback) {
|
||||||
|
|||||||
Reference in New Issue
Block a user