allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tvansteenbu...@apache.org
Subject [1/2] git commit: [#6795] single query for trove.children
Date Wed, 30 Oct 2013 05:39:10 GMT
Updated Branches:
  refs/heads/master 557761c53 -> a861a1570


[#6795] single query for trove.children

Additional 5.2x speedup (>14x total) of test_add_remove_label


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

Branch: refs/heads/master
Commit: a861a1570a8735104dd0a705a40452e2089ac436
Parents: e32c416
Author: Dave Brondsema <dbrondsema@slashdotmedia.com>
Authored: Fri Oct 25 00:17:31 2013 -0400
Committer: Tim Van Steenburgh <tvansteenburgh@gmail.com>
Committed: Wed Oct 30 05:38:31 2013 +0000

----------------------------------------------------------------------
 Allura/allura/model/project.py | 16 +++-------------
 1 file changed, 3 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/a861a157/Allura/allura/model/project.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/project.py b/Allura/allura/model/project.py
index 4dd3793..ff8c0f4 100644
--- a/Allura/allura/model/project.py
+++ b/Allura/allura/model/project.py
@@ -21,6 +21,7 @@ from collections import Counter, OrderedDict
 from datetime import datetime
 from copy import deepcopy
 import urllib
+import re
 
 from tg import config
 from pylons import tmpl_context as c, app_globals as g
@@ -87,7 +88,7 @@ class TroveCategory(MappedClass):
     class __mongometa__:
         session = main_orm_session
         name='trove_category'
-        indexes = [ 'trove_cat_id', 'trove_parent_id', 'shortname' ]
+        indexes = [ 'trove_cat_id', 'trove_parent_id', 'shortname', 'fullpath' ]
 
     _id=FieldProperty(S.ObjectId)
     trove_cat_id = FieldProperty(int, if_missing=None)
@@ -108,18 +109,7 @@ class TroveCategory(MappedClass):
 
     @property
     def children(self):
-        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
+        return self.query.find({'fullpath': re.compile('^' + re.escape(self.fullpath) + '
::')}).sort('fullpath')
 
     @property
     def type(self):


Mime
View raw message