mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-07-07 20:13:13 +02:00
use includes instead of indexOf
use _.uniq instead of filter&indexOf
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
'use strict';
|
||||
|
||||
var async = require('async');
|
||||
var _ = require('lodash');
|
||||
|
||||
var db = require('../database');
|
||||
var privileges = require('../privileges');
|
||||
|
||||
@@ -42,11 +44,8 @@ module.exports = function (Posts) {
|
||||
Posts.getPostsFields(pids, ['uid'], next);
|
||||
},
|
||||
function (postData, next) {
|
||||
var uids = postData.map(function (post) {
|
||||
return post && post.uid;
|
||||
}).filter(function (uid, index, array) {
|
||||
return uid && array.indexOf(uid) === index;
|
||||
});
|
||||
var uids = _.uniq(postData.map(post => post && post.uid).filter(uid => parseInt(uid, 10)));
|
||||
|
||||
next(null, uids);
|
||||
},
|
||||
], callback);
|
||||
|
||||
@@ -33,23 +33,20 @@ module.exports = function (Posts) {
|
||||
user.blocks.filter(uid, posts, next);
|
||||
},
|
||||
function (_posts, next) {
|
||||
var uids = [];
|
||||
var topicKeys = [];
|
||||
posts = _posts;
|
||||
var uids = {};
|
||||
var topicKeys = {};
|
||||
|
||||
posts.forEach(function (post, i) {
|
||||
if (uids.indexOf(posts[i].uid) === -1) {
|
||||
uids.push(posts[i].uid);
|
||||
}
|
||||
if (topicKeys.indexOf(posts[i].tid) === -1) {
|
||||
topicKeys.push(posts[i].tid);
|
||||
}
|
||||
posts.forEach(function (post) {
|
||||
uids[post.uid] = 1;
|
||||
topicKeys[post.tid] = 1;
|
||||
});
|
||||
async.parallel({
|
||||
users: function (next) {
|
||||
user.getUsersFields(uids, ['uid', 'username', 'userslug', 'picture'], next);
|
||||
user.getUsersFields(Object.keys(uids), ['uid', 'username', 'userslug', 'picture'], next);
|
||||
},
|
||||
topicsAndCategories: function (next) {
|
||||
getTopicAndCategories(topicKeys, next);
|
||||
getTopicAndCategories(Object.keys(topicKeys), next);
|
||||
},
|
||||
}, next);
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user