|
|
|
@ -23,11 +23,8 @@ module.exports = function (User) {
|
|
|
|
|
var searchResult = {};
|
|
|
|
|
async.waterfall([
|
|
|
|
|
function (next) {
|
|
|
|
|
if (data.findUids) {
|
|
|
|
|
data.findUids(query, searchBy, next);
|
|
|
|
|
} else {
|
|
|
|
|
findUids(query, searchBy, next);
|
|
|
|
|
}
|
|
|
|
|
var searchMethod = data.findUids || findUids;
|
|
|
|
|
searchMethod(query, searchBy, data.hardCap, next);
|
|
|
|
|
},
|
|
|
|
|
function (uids, next) {
|
|
|
|
|
filterAndSortUids(uids, data, next);
|
|
|
|
@ -57,7 +54,7 @@ module.exports = function (User) {
|
|
|
|
|
], callback);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
function findUids(query, searchBy, callback) {
|
|
|
|
|
function findUids(query, searchBy, hardCap, callback) {
|
|
|
|
|
if (!query) {
|
|
|
|
|
return callback(null, []);
|
|
|
|
|
}
|
|
|
|
@ -66,7 +63,7 @@ module.exports = function (User) {
|
|
|
|
|
var max = query.substr(0, query.length - 1) + String.fromCharCode(query.charCodeAt(query.length - 1) + 1);
|
|
|
|
|
|
|
|
|
|
var resultsPerPage = parseInt(meta.config.userSearchResultsPerPage, 10) || 20;
|
|
|
|
|
var hardCap = resultsPerPage * 10;
|
|
|
|
|
hardCap = hardCap || resultsPerPage * 10;
|
|
|
|
|
|
|
|
|
|
async.waterfall([
|
|
|
|
|
function (next) {
|
|
|
|
@ -82,9 +79,11 @@ module.exports = function (User) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function filterAndSortUids(uids, data, callback) {
|
|
|
|
|
var sortBy = data.sortBy || 'joindate';
|
|
|
|
|
var fields = [];
|
|
|
|
|
|
|
|
|
|
var fields = ['uid', sortBy];
|
|
|
|
|
if (data.sortBy) {
|
|
|
|
|
fields.push(data.sortBy);
|
|
|
|
|
}
|
|
|
|
|
if (data.onlineOnly) {
|
|
|
|
|
fields = fields.concat(['status', 'lastonline']);
|
|
|
|
|
}
|
|
|
|
@ -95,6 +94,12 @@ module.exports = function (User) {
|
|
|
|
|
fields.push('flags');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!fields.length) {
|
|
|
|
|
return callback(null, uids);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fields = ['uid'].concat(fields);
|
|
|
|
|
|
|
|
|
|
async.waterfall([
|
|
|
|
|
function (next) {
|
|
|
|
|
User.getUsersFields(uids, fields, next);
|
|
|
|
@ -118,7 +123,9 @@ module.exports = function (User) {
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sortUsers(userData, sortBy);
|
|
|
|
|
if (data.sortBy) {
|
|
|
|
|
sortUsers(userData, data.sortBy);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uids = userData.map(function (user) {
|
|
|
|
|
return user && user.uid;
|
|
|
|
|