Skip to content

Node.js based forum software built for the modern web

refactor to use getCidsByPrivilege

Barış Soner Uşaklı87b6808c4e02
diff --git a/src/categories.js b/src/categories.js
index 1270924f0e..1bbc80e599 100644
--- a/src/categories.js
+++ b/src/categories.js
@@ -95,7 +95,7 @@ Categories.getAllCategories = function (uid, callback) {
], callback);
};
-Categories.getCategoriesByPrivilege = function (set, uid, privilege, callback) {
+Categories.getCidsByPrivilege = function (set, uid, privilege, callback) {
async.waterfall([
function (next) {
db.getSortedSetRange(set, 0, -1, next);
@@ -103,6 +103,14 @@ Categories.getCategoriesByPrivilege = function (set, uid, privilege, callback) {
function (cids, next) {
privileges.categories.filterCids(privilege, cids, uid, next);
},
+ ], callback);
+};
+
+Categories.getCategoriesByPrivilege = function (set, uid, privilege, callback) {
+ async.waterfall([
+ function (next) {
+ Categories.getCidsByPrivilege(set, uid, privilege, next);
+ },
function (cids, next) {
Categories.getCategories(cids, uid, next);
},
diff --git a/src/search.js b/src/search.js
index 89f8cb66ab..5cb8263bc1 100644
--- a/src/search.js
+++ b/src/search.js
@@ -315,7 +315,7 @@ function filterByTags(posts, hasTags) {
var hasAllTags = false;
if (post && post.topic && Array.isArray(post.topic.tags) && post.topic.tags.length) {
hasAllTags = hasTags.every(function (tag) {
- return post.topic.tags.indexOf(tag) !== -1;
+ return post.topic.tags.includes(tag);
});
}
return hasAllTags;
@@ -370,23 +370,15 @@ function getSearchCids(data, callback) {
return callback(null, []);
}
- if (data.categories.indexOf('all') !== -1) {
- async.waterfall([
- function (next) {
- db.getSortedSetRange('categories:cid', 0, -1, next);
- },
- function (cids, next) {
- privileges.categories.filterCids('read', cids, data.uid, next);
- },
- ], callback);
- return;
+ if (data.categories.includes('all')) {
+ return categories.getCidsByPrivilege('categories:cid', data.uid, 'read', callback);
}
async.waterfall([
function (next) {
async.parallel({
watchedCids: function (next) {
- if (data.categories.indexOf('watched') !== -1) {
+ if (data.categories.includes('watched')) {
user.getWatchedCategories(data.uid, next);
} else {
next(null, []);