fix: dont send all category data back to recent&unread etc

v1.18.x
Barış Soner Uşaklı 6 years ago
parent ecf39727cc
commit 955e00fd9d

@ -4,6 +4,7 @@ const nconf = require('nconf');
const validator = require('validator'); const validator = require('validator');
const winston = require('winston'); const winston = require('winston');
const querystring = require('querystring'); const querystring = require('querystring');
const _ = require('lodash');
const user = require('../user'); const user = require('../user');
const privileges = require('../privileges'); const privileges = require('../privileges');
@ -228,7 +229,8 @@ async function getCategoryData(cids, uid, selectedCid) {
if (selectedCid && !Array.isArray(selectedCid)) { if (selectedCid && !Array.isArray(selectedCid)) {
selectedCid = [selectedCid]; selectedCid = [selectedCid];
} }
let categoryData = await categories.getCategoriesFields(cids, ['cid', 'order', 'name', 'slug', 'icon', 'link', 'color', 'bgColor', 'parentCid', 'image', 'imageClass']); const categoryFields = ['cid', 'order', 'name', 'slug', 'icon', 'link', 'color', 'bgColor', 'parentCid', 'image', 'imageClass'];
let categoryData = await categories.getCategoriesFields(cids, categoryFields);
categoryData = categoryData.filter(category => category && !category.link); categoryData = categoryData.filter(category => category && !category.link);
let selectedCategory = []; let selectedCategory = [];
@ -255,22 +257,17 @@ async function getCategoryData(cids, uid, selectedCid) {
selectedCategory = undefined; selectedCategory = undefined;
} }
const categoriesData = [];
const tree = categories.getTree(categoryData);
tree.forEach(category => recursive(category, categoriesData, '')); categories.getTree(categoryData);
const categoriesData = categories.buildForSelectCategories(categoryData);
return { categories: categoriesData, selectedCategory: selectedCategory, selectedCids: selectedCids }; return {
} categories: categoriesData.map(category => _.pick(category, [
'cid', 'name', 'icon', 'color', 'bgColor', 'parentCid', 'backgroundImage', 'imageClass', 'selected', 'level',
function recursive(category, categoriesData, level) { ])),
category.level = level; selectedCategory: selectedCategory,
categoriesData.push(category); selectedCids: selectedCids,
if (Array.isArray(category.children)) { };
category.children.forEach(function (child) {
recursive(child, categoriesData, '    ' + level);
});
}
} }
helpers.getHomePageRoutes = async function (uid) { helpers.getHomePageRoutes = async function (uid) {

Loading…
Cancel
Save