allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brond...@apache.org
Subject [1/2] git commit: [#6795] less mongo queries in trove.children
Date Fri, 25 Oct 2013 13:48:39 GMT
Updated Branches:
  refs/heads/db/6795 [created] 3b7e24478


[#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/aedfa0cb
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/aedfa0cb
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/aedfa0cb

Branch: refs/heads/db/6795
Commit: aedfa0cb5beafc4801ee734f72d2df43606893cf
Parents: 9a9dccd
Author: Dave Brondsema <dbrondsema@slashdotmedia.com>
Authored: Fri Oct 25 00:15:30 2013 -0400
Committer: Dave Brondsema <dbrondsema@slashdotmedia.com>
Committed: Fri Oct 25 09:46:43 2013 -0400

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


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/aedfa0cb/Allura/allura/model/project.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/project.py b/Allura/allura/model/project.py
index 5ac1810..c01cd7e 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