incubator-allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From john...@apache.org
Subject [35/40] git commit: [#6795] less mongo queries in trove.children
Date Wed, 30 Oct 2013 17:00:53 GMT
[#6795] less mongo queries in trove.children

In my local benchmark of running test_add_remove_label, this
gave a 2.8x speedup


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

Branch: refs/heads/cj/6777
Commit: e32c416fe40e5b908e60feac841e350028b7e7df
Parents: 557761c
Author: Dave Brondsema <dbrondsema@slashdotmedia.com>
Authored: Fri Oct 25 00:15:30 2013 -0400
Committer: Tim Van Steenburgh <tvansteenburgh@gmail.com>
Committed: Wed Oct 30 05:38:31 2013 +0000

----------------------------------------------------------------------
 Allura/allura/model/project.py | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/e32c416f/Allura/allura/model/project.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/project.py b/Allura/allura/model/project.py
index b9d310c..4dd3793 100644
--- a/Allura/allura/model/project.py
+++ b/Allura/allura/model/project.py
@@ -108,12 +108,17 @@ class TroveCategory(MappedClass):
 
     @property
     def children(self):
-        result = []
-        children = self.query.find(dict(trove_parent_id=self.trove_cat_id)).all()
-        for child in children:
-            result.append(child);
-            result.extend(child.children)
-        result.sort(key=lambda x:x.fullpath)
+        def recursive_children(cat_ids):
+            result = []
+            children = self.query.find({'trove_parent_id': {'$in': cat_ids}}).all()
+            for child in children:
+                result.append(child)
+            if children:
+                result.extend(recursive_children([c.trove_cat_id for c in children]))
+            return result
+
+        result = recursive_children([self.trove_cat_id])
+        result.sort(key=lambda x: x.fullpath)
         return result
 
     @property


Mime
View raw message