removed one of the timeouts in user search

v1.18.x
barisusakli 11 years ago
parent 770bf2bc44
commit b4dc2eebe9

@ -47,36 +47,34 @@ define(function() {
$('#user-notfound-notify').html('<i class="fa fa-spinner fa-spin"></i>'); $('#user-notfound-notify').html('<i class="fa fa-spinner fa-spin"></i>');
setTimeout(function() { socket.emit('user.search', username, function(err, data) {
socket.emit('user.search', username, function(err, data) { if(err) {
if(err) { return app.alert(err.message);
return app.alert(err.message); }
}
if (!data) {
if (!data) { $('#user-notfound-notify').html('You need to be logged in to search!');
$('#user-notfound-notify').html('You need to be logged in to search!'); $('#user-notfound-notify').parent().addClass('btn-warning label-warning');
$('#user-notfound-notify').parent().addClass('btn-warning label-warning'); return;
return; }
}
ajaxify.loadTemplate('users', function(usersTemplate) {
ajaxify.loadTemplate('users', function(usersTemplate) { var html = templates.parse(templates.getBlock(usersTemplate, 'users'), data);
var html = templates.parse(templates.getBlock(usersTemplate, 'users'), data);
translator.translate(html, function(translated) {
translator.translate(html, function(translated) { $('#users-container').html(translated);
$('#users-container').html(translated);
if (data && data.users.length === 0) {
if (data && data.users.length === 0) { $('#user-notfound-notify').html('User not found!');
$('#user-notfound-notify').html('User not found!'); $('#user-notfound-notify').parent().addClass('btn-warning label-warning');
$('#user-notfound-notify').parent().addClass('btn-warning label-warning'); } else {
} else { $('#user-notfound-notify').html(data.users.length + ' user' + (data.users.length > 1 ? 's' : '') + ' found! Search took ' + data.timing + ' ms.');
$('#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');
$('#user-notfound-notify').parent().addClass('btn-success label-success'); }
}
});
}); });
}); });
}, 500); //replace this with global throttling function/constant });
}, 250); }, 250);
}); });

@ -18,16 +18,21 @@ module.exports = function(User) {
query = query.toLowerCase(); query = query.toLowerCase();
var usernames = Object.keys(usernamesHash); var usernames = Object.keys(usernamesHash);
var uids = usernames.filter(function(username) { var uids = [];
return username.toLowerCase().indexOf(query) === 0;
}) for(var i=0; i<usernames.length; ++i) {
.slice(0, 10) if (usernames[i].toLowerCase().indexOf(query) === 0) {
.sort(function(a, b) { uids.push(usernames[i]);
return a > b; }
}) }
.map(function(username) {
return usernamesHash[username]; uids = uids.slice(0, 10)
}); .sort(function(a, b) {
return a > b;
})
.map(function(username) {
return usernamesHash[username];
});
User.getUsers(uids, function(err, userdata) { User.getUsers(uids, function(err, userdata) {
if (err) { if (err) {

Loading…
Cancel
Save