use includes instead of indexOf

use _.uniq instead of filter&indexOf
This commit is contained in:
Barış Soner Uşaklı
2018-10-20 14:40:48 -04:00
parent a6c70412db
commit 26d4e0852f
57 changed files with 156 additions and 208 deletions

View File

@@ -88,9 +88,8 @@ module.exports = function (privileges) {
},
function (_posts, next) {
postData = _posts;
tids = _.uniq(_posts.map(function (post) {
return post && post.tid;
}).filter(Boolean));
tids = _.uniq(_posts.map(post => post && post.tid).filter(Boolean));
topics.getTopicsFields(tids, ['deleted', 'cid'], next);
},
@@ -107,9 +106,9 @@ module.exports = function (privileges) {
post.topic = tidToTopic[post.tid];
}
return tidToTopic[post.tid] && tidToTopic[post.tid].cid;
}).filter(function (cid, index, array) {
return cid && array.indexOf(cid) === index;
});
}).filter(cid => parseInt(cid, 10));
cids = _.uniq(cids);
privileges.categories.getBase(privilege, cids, uid, next);
},
@@ -121,13 +120,12 @@ module.exports = function (privileges) {
(results.allowedTo[index] || results.isAdmin || results.isModerators[index]);
});
const cidsSet = new Set(cids);
pids = postData.filter(function (post) {
return post.topic && cids.indexOf(post.topic.cid) !== -1 &&
return post.topic && cidsSet.has(post.topic.cid) &&
((parseInt(post.topic.deleted, 10) !== 1 && parseInt(post.deleted, 10) !== 1) || results.isAdmin || isModOf[post.cid]);
}).map(function (post) {
return post.pid;
});
}).map(post => post.pid);
plugins.fireHook('filter:privileges.posts.filter', {
privilege: privilege,