You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by jo...@apache.org on 2012/10/11 21:58:52 UTC
[17/21] git commit: [#5047] Improve efficiency of user search query
[#5047] Improve efficiency of user search query
Signed-off-by: Cory Johns <jo...@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/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 <jo...@geek.net>
Authored: Mon Oct 8 21:44:34 2012 +0000
Committer: Dave Brondsema <db...@geek.net>
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):