Return-Path: X-Original-To: apmail-incubator-allura-commits-archive@minotaur.apache.org Delivered-To: apmail-incubator-allura-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id BAEF7D1DD for ; Thu, 11 Oct 2012 19:58:52 +0000 (UTC) Received: (qmail 47712 invoked by uid 500); 11 Oct 2012 19:58:52 -0000 Delivered-To: apmail-incubator-allura-commits-archive@incubator.apache.org Received: (qmail 47657 invoked by uid 500); 11 Oct 2012 19:58:52 -0000 Mailing-List: contact allura-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: allura-dev@incubator.apache.org Delivered-To: mailing list allura-commits@incubator.apache.org Received: (qmail 47452 invoked by uid 99); 11 Oct 2012 19:58:52 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 11 Oct 2012 19:58:52 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 2D2143DAEE; Thu, 11 Oct 2012 19:58:52 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: johnsca@apache.org To: allura-commits@incubator.apache.org X-Mailer: ASF-Git Admin Mailer Subject: [17/21] git commit: [#5047] Improve efficiency of user search query Message-Id: <20121011195852.2D2143DAEE@tyr.zones.apache.org> Date: Thu, 11 Oct 2012 19:58:52 +0000 (UTC) [#5047] Improve efficiency of user search query Signed-off-by: Cory Johns Project: http://git-wip-us.apache.org/repos/asf/incubator-allura/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-allura/commit/f5556c14 Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/f5556c14 Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/f5556c14 Branch: refs/heads/cj/4942 Commit: f5556c14d60bf77b2efc9e0d32287581b03f2dd3 Parents: edbe8b8 Author: Cory Johns Authored: Mon Oct 8 21:44:34 2012 +0000 Committer: Dave Brondsema Committed: Tue Oct 9 17:07:24 2012 +0000 ---------------------------------------------------------------------- Allura/allura/controllers/project.py | 17 +++++------------ 1 files changed, 5 insertions(+), 12 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/f5556c14/Allura/allura/controllers/project.py ---------------------------------------------------------------------- diff --git a/Allura/allura/controllers/project.py b/Allura/allura/controllers/project.py index f833a71..021b9cf 100644 --- a/Allura/allura/controllers/project.py +++ b/Allura/allura/controllers/project.py @@ -340,27 +340,20 @@ class ProjectController(object): def user_search(self, term=''): if len(term) < 3: raise exc.HTTPBadRequest('"term" param must be at least length 3') - users = M.User.by_display_name(term) named_roles = RoleCache( g.credentials, g.credentials.project_roles(project_id=c.project.root_project._id).named) - result = [ [], [] ] - for u in users: - if u._id in named_roles.userids_that_reach: - result[0].append(u) - else: - pass - # comment this back in if you want non-project-member users - # in the search results - #result[1].append(u) - result = list(islice(chain(*result), 10)) + users = M.User.query.find({ + '_id': {'$in': named_roles.userids_that_reach}, + 'display_name': re.compile(r'(?i)%s' % re.escape(term)), + }).sort('username').limit(10).all() return dict( users=[ dict( label='%s (%s)' % (u.get_pref('display_name'), u.username), value=u.username, id=u.username) - for u in result]) + for u in users]) class ScreenshotsController(object):