Changeset - 7e221629a3e5
[Not reviewed]
beta
0 1 0
Marcin Kuzminski - 14 years ago 2011-06-16 23:00:19
marcin@python-works.com
#209 Added recursive count on repositories to calculate all repos within all nested groups
1 file changed with 19 insertions and 3 deletions:
0 comments (0 inline, 0 general)
rhodecode/model/db.py
Show inline comments
 
@@ -468,7 +468,7 @@ class Group(Base):
 

	
 
    @property
 
    def parents(self):
 
        parents_limit = 5
 
        parents_recursion_limit = 5
 
        groups = []
 
        if self.parent_group is None:
 
            return groups
 
@@ -481,15 +481,18 @@ class Group(Base):
 
            cur_gr = cur_gr.parent_group
 
            if gr is None:
 
                break
 
            if cnt == parents_limit:
 
            if cnt == parents_recursion_limit:
 
                # this will prevent accidental infinit loops
 
                log.error('group nested more than %s' %
 
                                parents_limit)
 
                          parents_recursion_limit)
 
                break
 

	
 
            groups.insert(0, gr)
 
        return groups
 

	
 
    @property
 
    def children(self):
 
        return Session.query(Group).filter(Group.parent_group == self)
 

	
 
    @property
 
    def full_path(self):
 
@@ -500,6 +503,19 @@ class Group(Base):
 
    def repositories(self):
 
        return Session.query(Repository).filter(Repository.group == self)
 

	
 
    @property
 
    def repositories_recursive_count(self):
 
        cnt = self.repositories.count()
 

	
 
        def children_count(group):
 
            cnt = 0
 
            for child in group.children:
 
                cnt += child.repositories.count()
 
                cnt += children_count(child)
 
            return cnt
 

	
 
        return cnt + children_count(self)
 

	
 
class Permission(Base):
 
    __tablename__ = 'permissions'
 
    __table_args__ = {'extend_existing':True}
0 comments (0 inline, 0 general)