perf: use only required calls

v1.18.x
Barış Soner Uşaklı 4 years ago
parent a51c5698c7
commit f0dd302c77

@ -106,8 +106,14 @@ module.exports = function (privileges) {
}
cids = _.uniq(cids);
const results = await privileges.categories.getBase(privilege, cids, uid);
return cids.filter((cid, index) => !!cid && !results.categories[index].disabled && (results.allowedTo[index] || results.isAdmin));
const [categoryData, allowedTo, isAdmin] = await Promise.all([
categories.getCategoriesFields(cids, ['disabled']),
helpers.isAllowedTo(privilege, uid, cids),
user.isAdministrator(uid),
]);
return cids.filter(
(cid, index) => !!cid && !categoryData[index].disabled && (allowedTo[index] || isAdmin)
);
};
privileges.categories.getBase = async function (privilege, cids, uid) {

Loading…
Cancel
Save