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 2014/02/18 00:21:36 UTC

git commit: [#7181] Optimization for reaching_roles query

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 <cj...@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 <cj...@slashdotmedia.com>
Authored: Mon Feb 17 23:18:37 2014 +0000
Committer: Cory Johns <cj...@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