From 307abaa8cc2f44495f9b3a640b0bf7fce14aa3b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Fri, 20 Sep 2019 02:12:15 -0400 Subject: [PATCH] fix: only return necessary data for categories --- src/categories/index.js | 8 ++------ src/controllers/search.js | 10 ++++++++-- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/categories/index.js b/src/categories/index.js index 06279d976f..37eae5c874 100644 --- a/src/categories/index.js +++ b/src/categories/index.js @@ -341,9 +341,7 @@ Categories.buildForSelectCategories = function (categories) { category.depth = depth; categoriesData.push(category); if (Array.isArray(category.children)) { - category.children.forEach(function (child) { - recursive(child, categoriesData, '    ' + level, depth + 1); - }); + category.children.forEach(child => recursive(child, categoriesData, '    ' + level, depth + 1)); } } @@ -351,9 +349,7 @@ Categories.buildForSelectCategories = function (categories) { categories = categories.filter(category => category && !category.parentCid); - categories.forEach(function (category) { - recursive(category, categoriesData, '', 0); - }); + categories.forEach(category => recursive(category, categoriesData, '', 0)); return categoriesData; }; diff --git a/src/controllers/search.js b/src/controllers/search.js index 5caef07d92..1b46e121a8 100644 --- a/src/controllers/search.js +++ b/src/controllers/search.js @@ -84,8 +84,14 @@ async function buildCategories(uid, searchOnly) { if (searchOnly) { return []; } - let categoriesData = await categories.buildForSelect(uid, 'read'); - categoriesData = categoriesData.filter(category => category && !category.link); + + const cids = await categories.getCidsByPrivilege('categories:cid', uid, 'read'); + let categoriesData = await categories.getCategoriesData(cids); + categoriesData = categories.getTree(categoriesData); + categoriesData = categories.buildForSelectCategories(categoriesData); + + categoriesData = categoriesData.filter(category => category && !category.link) + .map(category => ({ value: category.value, text: category.text })); return [ { value: 'all', text: '[[unread:all_categories]]' }, { value: 'watched', text: '[[category:watched-categories]]' },