mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-01 11:35:55 +01:00
use _.uniq
This commit is contained in:
@@ -28,11 +28,9 @@ module.exports = function (Posts) {
|
|||||||
},
|
},
|
||||||
function (_postData, next) {
|
function (_postData, next) {
|
||||||
postData = _postData;
|
postData = _postData;
|
||||||
tids = postData.map(function (post) {
|
tids = _.uniq(postData.map(function (post) {
|
||||||
return post.tid;
|
return post && post.tid;
|
||||||
}).filter(function (tid, index, array) {
|
}).filter(Boolean));
|
||||||
return tid && array.indexOf(tid) === index;
|
|
||||||
});
|
|
||||||
|
|
||||||
topics.getTopicsFields(tids, ['cid'], next);
|
topics.getTopicsFields(tids, ['cid'], next);
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -232,9 +232,7 @@ module.exports = function (privileges) {
|
|||||||
return callback(null, []);
|
return callback(null, []);
|
||||||
}
|
}
|
||||||
|
|
||||||
cids = cids.filter(function (cid, index, array) {
|
cids = _.uniq(cids);
|
||||||
return array.indexOf(cid) === index;
|
|
||||||
});
|
|
||||||
|
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
function (next) {
|
function (next) {
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var async = require('async');
|
var async = require('async');
|
||||||
|
var _ = require('lodash');
|
||||||
|
|
||||||
var meta = require('../meta');
|
var meta = require('../meta');
|
||||||
var posts = require('../posts');
|
var posts = require('../posts');
|
||||||
@@ -72,17 +73,18 @@ module.exports = function (privileges) {
|
|||||||
var tids;
|
var tids;
|
||||||
var tidToTopic = {};
|
var tidToTopic = {};
|
||||||
|
|
||||||
|
pids = _.uniq(pids);
|
||||||
|
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
function (next) {
|
function (next) {
|
||||||
posts.getPostsFields(pids, ['uid', 'tid', 'deleted'], next);
|
posts.getPostsFields(pids, ['uid', 'tid', 'deleted'], next);
|
||||||
},
|
},
|
||||||
function (_posts, next) {
|
function (_posts, next) {
|
||||||
postData = _posts;
|
postData = _posts;
|
||||||
tids = _posts.map(function (post) {
|
tids = _.uniq(_posts.map(function (post) {
|
||||||
return post && post.tid;
|
return post && post.tid;
|
||||||
}).filter(function (tid, index, array) {
|
}).filter(Boolean));
|
||||||
return tid && array.indexOf(tid) === index;
|
|
||||||
});
|
|
||||||
topics.getTopicsFields(tids, ['deleted', 'cid'], next);
|
topics.getTopicsFields(tids, ['deleted', 'cid'], next);
|
||||||
},
|
},
|
||||||
function (topicData, next) {
|
function (topicData, next) {
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var async = require('async');
|
var async = require('async');
|
||||||
|
var _ = require('lodash');
|
||||||
|
|
||||||
var user = require('../user');
|
var user = require('../user');
|
||||||
var groups = require('../groups');
|
var groups = require('../groups');
|
||||||
@@ -51,9 +52,7 @@ module.exports = function (privileges) {
|
|||||||
return filterIsModerator(cids, uid, cids.map(function () { return true; }), callback);
|
return filterIsModerator(cids, uid, cids.map(function () { return true; }), callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
uniqueCids = cids.filter(function (cid, index, array) {
|
uniqueCids = _.uniq(cids);
|
||||||
return array.indexOf(cid) === index;
|
|
||||||
});
|
|
||||||
|
|
||||||
helpers.isUserAllowedTo('moderate', uid, uniqueCids, next);
|
helpers.isUserAllowedTo('moderate', uid, uniqueCids, next);
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var async = require('async');
|
var async = require('async');
|
||||||
|
var _ = require('lodash');
|
||||||
|
|
||||||
var db = require('./database');
|
var db = require('./database');
|
||||||
var posts = require('./posts');
|
var posts = require('./posts');
|
||||||
@@ -79,9 +80,7 @@ function searchInContent(data, callback) {
|
|||||||
function (mainPids, next) {
|
function (mainPids, next) {
|
||||||
pids = mainPids.concat(pids).map(function (pid) {
|
pids = mainPids.concat(pids).map(function (pid) {
|
||||||
return pid && pid.toString();
|
return pid && pid.toString();
|
||||||
}).filter(function (pid, index, array) {
|
}).filter(Boolean);
|
||||||
return pid && array.indexOf(pid) === index;
|
|
||||||
});
|
|
||||||
|
|
||||||
privileges.posts.filter('read', pids, data.uid, next);
|
privileges.posts.filter('read', pids, data.uid, next);
|
||||||
},
|
},
|
||||||
@@ -392,9 +391,8 @@ function getSearchCids(data, callback) {
|
|||||||
}, next);
|
}, next);
|
||||||
},
|
},
|
||||||
function (results, next) {
|
function (results, next) {
|
||||||
var cids = results.watchedCids.concat(results.childrenCids).concat(data.categories).filter(function (cid, index, array) {
|
var cids = results.watchedCids.concat(results.childrenCids).concat(data.categories).filter(Boolean);
|
||||||
return cid && array.indexOf(cid) === index;
|
cids = _.uniq(cids);
|
||||||
});
|
|
||||||
next(null, cids);
|
next(null, cids);
|
||||||
},
|
},
|
||||||
], callback);
|
], callback);
|
||||||
|
|||||||
@@ -101,14 +101,14 @@ Topics.getTopicsByTids = function (tids, uid, callback) {
|
|||||||
function mapFilter(array, field) {
|
function mapFilter(array, field) {
|
||||||
return array.map(function (topic) {
|
return array.map(function (topic) {
|
||||||
return topic && topic[field] && topic[field].toString();
|
return topic && topic[field] && topic[field].toString();
|
||||||
}).filter(function (value, index, array) {
|
}).filter(function (value) {
|
||||||
return utils.isNumber(value) && array.indexOf(value) === index;
|
return utils.isNumber(value);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
topics = _topics;
|
topics = _topics;
|
||||||
uids = mapFilter(topics, 'uid');
|
uids = _.uniq(mapFilter(topics, 'uid'));
|
||||||
cids = mapFilter(topics, 'cid');
|
cids = _.uniq(mapFilter(topics, 'cid'));
|
||||||
|
|
||||||
async.parallel({
|
async.parallel({
|
||||||
users: function (next) {
|
users: function (next) {
|
||||||
|
|||||||
@@ -25,8 +25,8 @@ module.exports = function (Topics) {
|
|||||||
},
|
},
|
||||||
function (results, next) {
|
function (results, next) {
|
||||||
var tids = results.tagTids.concat(results.searchTids).concat(results.categoryTids);
|
var tids = results.tagTids.concat(results.searchTids).concat(results.categoryTids);
|
||||||
tids = tids.filter(function (_tid, index, array) {
|
tids = _.uniq(tids).filter(function (_tid) {
|
||||||
return parseInt(_tid, 10) !== parseInt(tid, 10) && array.indexOf(_tid) === index;
|
return parseInt(_tid, 10) !== parseInt(tid, 10);
|
||||||
});
|
});
|
||||||
|
|
||||||
if (stop === -1) {
|
if (stop === -1) {
|
||||||
|
|||||||
@@ -23,11 +23,12 @@ module.exports = function (Topics) {
|
|||||||
plugins.fireHook('filter:tags.filter', { tags: tags, tid: tid }, next);
|
plugins.fireHook('filter:tags.filter', { tags: tags, tid: tid }, next);
|
||||||
},
|
},
|
||||||
function (data, next) {
|
function (data, next) {
|
||||||
tags = data.tags.slice(0, meta.config.maximumTagsPerTopic || 5);
|
tags = _.uniq(data.tags);
|
||||||
|
tags = tags.slice(0, meta.config.maximumTagsPerTopic || 5);
|
||||||
tags = tags.map(function (tag) {
|
tags = tags.map(function (tag) {
|
||||||
return utils.cleanUpTag(tag, meta.config.maximumTagLength);
|
return utils.cleanUpTag(tag, meta.config.maximumTagLength);
|
||||||
}).filter(function (tag, index, array) {
|
}).filter(function (tag) {
|
||||||
return tag && tag.length >= (meta.config.minimumTagLength || 3) && array.indexOf(tag) === index;
|
return tag && tag.length >= (meta.config.minimumTagLength || 3);
|
||||||
});
|
});
|
||||||
|
|
||||||
filterCategoryTags(tags, tid, next);
|
filterCategoryTags(tags, tid, next);
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var async = require('async');
|
var async = require('async');
|
||||||
|
var _ = require('lodash');
|
||||||
var S = require('string');
|
var S = require('string');
|
||||||
var winston = require('winston');
|
var winston = require('winston');
|
||||||
|
|
||||||
@@ -57,11 +58,9 @@ module.exports = function (Topics) {
|
|||||||
},
|
},
|
||||||
function (_postData, next) {
|
function (_postData, next) {
|
||||||
postData = _postData;
|
postData = _postData;
|
||||||
var uids = postData.map(function (post) {
|
var uids = _.uniq(postData.map(function (post) {
|
||||||
return post.uid;
|
return post.uid;
|
||||||
}).filter(function (uid, index, array) {
|
}));
|
||||||
return array.indexOf(uid) === index;
|
|
||||||
});
|
|
||||||
|
|
||||||
user.getUsersFields(uids, ['uid', 'username', 'userslug', 'picture'], next);
|
user.getUsersFields(uids, ['uid', 'username', 'userslug', 'picture'], next);
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var async = require('async');
|
var async = require('async');
|
||||||
|
var _ = require('lodash');
|
||||||
|
|
||||||
var db = require('../database');
|
var db = require('../database');
|
||||||
var user = require('../user');
|
var user = require('../user');
|
||||||
@@ -118,10 +119,10 @@ module.exports = function (Topics) {
|
|||||||
}
|
}
|
||||||
}).map(function (topic) {
|
}).map(function (topic) {
|
||||||
return topic.value;
|
return topic.value;
|
||||||
}).filter(function (tid, index, array) {
|
|
||||||
return array.indexOf(tid) === index;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
tids = _.uniq(tids);
|
||||||
|
|
||||||
if (params.filter === 'watched') {
|
if (params.filter === 'watched') {
|
||||||
Topics.filterWatchedTids(tids, uid, next);
|
Topics.filterWatchedTids(tids, uid, next);
|
||||||
} else {
|
} else {
|
||||||
@@ -222,8 +223,8 @@ module.exports = function (Topics) {
|
|||||||
return setImmediate(callback, null, false);
|
return setImmediate(callback, null, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
tids = tids.filter(function (tid, index, array) {
|
tids = _.uniq(tids).filter(function (tid) {
|
||||||
return tid && utils.isNumber(tid) && array.indexOf(tid) === index;
|
return tid && utils.isNumber(tid);
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!tids.length) {
|
if (!tids.length) {
|
||||||
@@ -260,9 +261,9 @@ module.exports = function (Topics) {
|
|||||||
function (results, next) {
|
function (results, next) {
|
||||||
var cids = results.topicData.map(function (topic) {
|
var cids = results.topicData.map(function (topic) {
|
||||||
return topic && topic.cid;
|
return topic && topic.cid;
|
||||||
}).filter(function (topic, index, array) {
|
}).filter(Boolean);
|
||||||
return topic && array.indexOf(topic) === index;
|
|
||||||
});
|
cids = _.uniq(cids);
|
||||||
|
|
||||||
categories.markAsRead(cids, uid, next);
|
categories.markAsRead(cids, uid, next);
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -64,9 +64,7 @@ User.getUsersWithFields = function (uids, fields, uid, callback) {
|
|||||||
plugins.fireHook('filter:users.addFields', { fields: fields }, next);
|
plugins.fireHook('filter:users.addFields', { fields: fields }, next);
|
||||||
},
|
},
|
||||||
function (data, next) {
|
function (data, next) {
|
||||||
data.fields = data.fields.filter(function (field, index, array) {
|
data.fields = _.uniq(data.fields);
|
||||||
return array.indexOf(field) === index;
|
|
||||||
});
|
|
||||||
|
|
||||||
async.parallel({
|
async.parallel({
|
||||||
userData: function (next) {
|
userData: function (next) {
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var async = require('async');
|
var async = require('async');
|
||||||
|
var _ = require('lodash');
|
||||||
|
|
||||||
var db = require('../database');
|
var db = require('../database');
|
||||||
var posts = require('../posts');
|
var posts = require('../posts');
|
||||||
@@ -152,9 +153,7 @@ module.exports = function (User) {
|
|||||||
}, next);
|
}, next);
|
||||||
},
|
},
|
||||||
function (pids, next) {
|
function (pids, next) {
|
||||||
pids = pids.upvotedPids.concat(pids.downvotedPids).filter(function (pid, index, array) {
|
pids = _.uniq(pids.upvotedPids.concat(pids.downvotedPids).filter(Boolean));
|
||||||
return pid && array.indexOf(pid) === index;
|
|
||||||
});
|
|
||||||
|
|
||||||
async.eachSeries(pids, function (pid, next) {
|
async.eachSeries(pids, function (pid, next) {
|
||||||
posts.unvote(pid, uid, next);
|
posts.unvote(pid, uid, next);
|
||||||
|
|||||||
Reference in New Issue
Block a user