incubator-allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From john...@apache.org
Subject git commit: [#5047] Improve efficiency of user search query
Date Mon, 08 Oct 2012 21:49:10 GMT
Updated Branches:
  refs/heads/cj/5047 [created] 31eea4cda


[#5047] Improve efficiency of user search query

Signed-off-by: Cory Johns <johnsca@geek.net>


Project: http://git-wip-us.apache.org/repos/asf/incubator-allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-allura/commit/31eea4cd
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/31eea4cd
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/31eea4cd

Branch: refs/heads/cj/5047
Commit: 31eea4cda849cd3aa4bd62173b0781298eff744b
Parents: 0c25b52
Author: Cory Johns <johnsca@geek.net>
Authored: Mon Oct 8 21:44:34 2012 +0000
Committer: Cory Johns <johnsca@geek.net>
Committed: Mon Oct 8 21:44:34 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/31eea4cd/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):
 


Mime
View raw message