From 5c091437da87014c752f62e02c8d092e44e5a9fe Mon Sep 17 00:00:00 2001 From: Steve Howell Date: Thu, 26 Jan 2017 05:21:44 -0800 Subject: [PATCH] Improve empty user filter handling for stream creates. If we blank out the user filter for users (by hitting backspace, for example), then we now have short-circuit logic to display all the user checkboxes. (The user-facing behavior doesn't change here, but now we don't have to process all the strings.) --- static/js/subs.js | 42 +++++++++++++++++++++++++----------------- 1 file changed, 25 insertions(+), 17 deletions(-) diff --git a/static/js/subs.js b/static/js/subs.js index db84780720..90f4a1f333 100644 --- a/static/js/subs.js +++ b/static/js/subs.js @@ -925,24 +925,32 @@ $(function () { } }); - var users = people.get_rest_of_realm(); - var filtered_users = people.filter_people_by_search_terms(users, search_terms); - var user_labels = $("#user-checkboxes label.add-user-label"); + (function filter_user_checkboxes() { + var user_labels = $("#user-checkboxes label.add-user-label"); - // Be careful about modifying the follow code. A naive implementation - // will work very poorly with a large user population (~1000 users). - // - // I tested using: `./manage.py populate_db --extra-users 3500` - // - // This would break the previous implementation, whereas the new - // implementation is merely sluggish. - user_labels.each(function () { - var elem = $(this); - var user_id = elem.attr('data-user-id'); - var user_checked = filtered_users.has(user_id); - var display = user_checked ? "block" : "none"; - elem.css({display: display}); - }); + if (search_term === '') { + user_labels.css({display: 'block'}); + return; + } + + var users = people.get_rest_of_realm(); + var filtered_users = people.filter_people_by_search_terms(users, search_terms); + + // Be careful about modifying the follow code. A naive implementation + // will work very poorly with a large user population (~1000 users). + // + // I tested using: `./manage.py populate_db --extra-users 3500` + // + // This would break the previous implementation, whereas the new + // implementation is merely sluggish. + user_labels.each(function () { + var elem = $(this); + var user_id = elem.attr('data-user-id'); + var user_checked = filtered_users.has(user_id); + var display = user_checked ? "block" : "none"; + elem.css({display: display}); + }); + }()); update_announce_stream_state(); e.preventDefault();