faster sort users

v1.18.x
barisusakli 10 years ago
parent 0fab6c243c
commit f9fecf4bc1

@ -178,19 +178,21 @@ module.exports = function(User) {
} }
function sortUsers(userData, sortBy) { function sortUsers(userData, sortBy) {
userData.sort(function(user1, user2) {
if (sortBy === 'joindate' || sortBy === 'postcount') { if (sortBy === 'joindate' || sortBy === 'postcount') {
return user2[sortBy] - user1[sortBy]; userData.sort(function(u1, u2) {
return u2[sortBy] - u1[sortBy];
});
} else { } else {
if(user1[sortBy] < user2[sortBy]) { userData.sort(function(u1, u2) {
if(u1[sortBy] < u2[sortBy]) {
return -1; return -1;
} else if(user1[sortBy] > user2[sortBy]) { } else if(u1[sortBy] > u2[sortBy]) {
return 1; return 1;
} }
return 0; return 0;
}
}); });
} }
}
function searchByIP(ip, callback) { function searchByIP(ip, callback) {
var start = process.hrtime(); var start = process.hrtime();

Loading…
Cancel
Save