From f9fecf4bc1a18f576a3bd29742c75cead662a603 Mon Sep 17 00:00:00 2001 From: barisusakli Date: Wed, 28 Jan 2015 19:19:55 -0500 Subject: [PATCH] faster sort users --- src/user/search.js | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/user/search.js b/src/user/search.js index bad43be25b..95130bf68f 100644 --- a/src/user/search.js +++ b/src/user/search.js @@ -178,18 +178,20 @@ module.exports = function(User) { } function sortUsers(userData, sortBy) { - userData.sort(function(user1, user2) { - if (sortBy === 'joindate' || sortBy === 'postcount') { - return user2[sortBy] - user1[sortBy]; - } else { - if(user1[sortBy] < user2[sortBy]) { + if (sortBy === 'joindate' || sortBy === 'postcount') { + userData.sort(function(u1, u2) { + return u2[sortBy] - u1[sortBy]; + }); + } else { + userData.sort(function(u1, u2) { + if(u1[sortBy] < u2[sortBy]) { return -1; - } else if(user1[sortBy] > user2[sortBy]) { + } else if(u1[sortBy] > u2[sortBy]) { return 1; } return 0; - } - }); + }); + } } function searchByIP(ip, callback) {