From b4dc2eebe9db9d55ef1386529abe5140eeeac692 Mon Sep 17 00:00:00 2001 From: barisusakli Date: Fri, 18 Apr 2014 12:46:46 -0400 Subject: [PATCH] removed one of the timeouts in user search --- public/src/forum/users.js | 54 +++++++++++++++++++-------------------- src/user/search.js | 25 ++++++++++-------- 2 files changed, 41 insertions(+), 38 deletions(-) diff --git a/public/src/forum/users.js b/public/src/forum/users.js index d4192d30c1..898d6ac90c 100644 --- a/public/src/forum/users.js +++ b/public/src/forum/users.js @@ -47,36 +47,34 @@ define(function() { $('#user-notfound-notify').html(''); - setTimeout(function() { - socket.emit('user.search', username, function(err, data) { - if(err) { - return app.alert(err.message); - } - - if (!data) { - $('#user-notfound-notify').html('You need to be logged in to search!'); - $('#user-notfound-notify').parent().addClass('btn-warning label-warning'); - return; - } - - ajaxify.loadTemplate('users', function(usersTemplate) { - var html = templates.parse(templates.getBlock(usersTemplate, 'users'), data); - - translator.translate(html, function(translated) { - $('#users-container').html(translated); - - - if (data && data.users.length === 0) { - $('#user-notfound-notify').html('User not found!'); - $('#user-notfound-notify').parent().addClass('btn-warning label-warning'); - } else { - $('#user-notfound-notify').html(data.users.length + ' user' + (data.users.length > 1 ? 's' : '') + ' found! Search took ' + data.timing + ' ms.'); - $('#user-notfound-notify').parent().addClass('btn-success label-success'); - } - }); + socket.emit('user.search', username, function(err, data) { + if(err) { + return app.alert(err.message); + } + + if (!data) { + $('#user-notfound-notify').html('You need to be logged in to search!'); + $('#user-notfound-notify').parent().addClass('btn-warning label-warning'); + return; + } + + ajaxify.loadTemplate('users', function(usersTemplate) { + var html = templates.parse(templates.getBlock(usersTemplate, 'users'), data); + + translator.translate(html, function(translated) { + $('#users-container').html(translated); + + + if (data && data.users.length === 0) { + $('#user-notfound-notify').html('User not found!'); + $('#user-notfound-notify').parent().addClass('btn-warning label-warning'); + } else { + $('#user-notfound-notify').html(data.users.length + ' user' + (data.users.length > 1 ? 's' : '') + ' found! Search took ' + data.timing + ' ms.'); + $('#user-notfound-notify').parent().addClass('btn-success label-success'); + } }); }); - }, 500); //replace this with global throttling function/constant + }); }, 250); }); diff --git a/src/user/search.js b/src/user/search.js index c014435a97..a4d187cf60 100644 --- a/src/user/search.js +++ b/src/user/search.js @@ -18,16 +18,21 @@ module.exports = function(User) { query = query.toLowerCase(); var usernames = Object.keys(usernamesHash); - var uids = usernames.filter(function(username) { - return username.toLowerCase().indexOf(query) === 0; - }) - .slice(0, 10) - .sort(function(a, b) { - return a > b; - }) - .map(function(username) { - return usernamesHash[username]; - }); + var uids = []; + + for(var i=0; i b; + }) + .map(function(username) { + return usernamesHash[username]; + }); User.getUsers(uids, function(err, userdata) { if (err) {