Mercurial > kallithea
changeset 1385:7e221629a3e5 beta
#209 Added recursive count on repositories to calculate all repos within all nested groups
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Thu, 16 Jun 2011 23:00:19 +0200 |
parents | 4fd86e3deccf |
children | 5a31d387f347 |
files | rhodecode/model/db.py |
diffstat | 1 files changed, 19 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/rhodecode/model/db.py Thu Jun 16 20:05:13 2011 +0200 +++ b/rhodecode/model/db.py Thu Jun 16 23:00:19 2011 +0200 @@ -468,7 +468,7 @@ @property def parents(self): - parents_limit = 5 + parents_recursion_limit = 5 groups = [] if self.parent_group is None: return groups @@ -481,15 +481,18 @@ 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 @@ 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}