incubator-allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From john...@apache.org
Subject git commit: [#7181] Optimization for reaching_roles query
Date Mon, 17 Feb 2014 23:21:36 GMT
Repository: incubator-allura
Updated Branches:
  refs/heads/cj/7181 0a6523071 -> b562c7469


[#7181] Optimization for reaching_roles query

When following role reference chains (i.e., reaching), we can exclude
unnamed roles from the project_role index because no named nor unnamed
role will ever point to an unnamed (i.e., user) role.

Signed-off-by: Cory Johns <cjohns@slashdotmedia.com>


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

Branch: refs/heads/cj/7181
Commit: b562c7469b6e4405fd858095a872de82dd6a50b5
Parents: 0a65230
Author: Cory Johns <cjohns@slashdotmedia.com>
Authored: Mon Feb 17 23:18:37 2014 +0000
Committer: Cory Johns <cjohns@slashdotmedia.com>
Committed: Mon Feb 17 23:18:56 2014 +0000

----------------------------------------------------------------------
 Allura/allura/lib/security.py | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/b562c746/Allura/allura/lib/security.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/security.py b/Allura/allura/lib/security.py
index edd74d9..6a1b0ce 100644
--- a/Allura/allura/lib/security.py
+++ b/Allura/allura/lib/security.py
@@ -234,17 +234,20 @@ class RoleCache(object):
     def reaching_roles(self):
         def _iter():
             to_visit = self.index.items()
+            project_ids = set([r['project_id'] for _id, r in to_visit])
+            pr_index = {r._id: r for r in self.cred.project_role.find({
+                'project_id': {'$in': list(project_ids)},
+                'user_id': None,
+            })}
             visited = set()
             while to_visit:
                 (rid, role) = to_visit.pop()
                 if rid in visited:
                     continue
                 yield role
-                pr_index = self.cred.project_roles(role['project_id']).index
-                if rid in pr_index:
-                    for i in pr_index[rid]['roles']:
-                        if i in pr_index:
-                            to_visit.append((i, pr_index[i]))
+                for i in role['roles']:
+                    if i in pr_index:
+                        to_visit.append((i, pr_index[i]))
         return RoleCache(self.cred, _iter())
 
     @LazyProperty


Mime
View raw message