comparison rhodecode/controllers/changelog.py @ 1884:0614862a20ec beta

Added number of comments in changelog for each changeset - significantly improved speed of changelog page for large repos
author Marcin Kuzminski <marcin@python-works.com>
date Wed, 11 Jan 2012 17:59:15 +0200
parents baef43bc457c
children 324ac367a4da
comparison
equal deleted inserted replaced
1883:69d3c4450944 1884:0614862a20ec
36 from rhodecode.lib.base import BaseRepoController, render 36 from rhodecode.lib.base import BaseRepoController, render
37 from rhodecode.lib.helpers import RepoPage 37 from rhodecode.lib.helpers import RepoPage
38 from rhodecode.lib.compat import json 38 from rhodecode.lib.compat import json
39 39
40 from vcs.exceptions import RepositoryError, ChangesetDoesNotExistError 40 from vcs.exceptions import RepositoryError, ChangesetDoesNotExistError
41 from rhodecode.model.db import Repository
41 42
42 log = logging.getLogger(__name__) 43 log = logging.getLogger(__name__)
43 44
44 45
45 class ChangelogController(BaseRepoController): 46 class ChangelogController(BaseRepoController):
73 collection = [z for z in 74 collection = [z for z in
74 c.rhodecode_repo.get_changesets(start=0, 75 c.rhodecode_repo.get_changesets(start=0,
75 branch_name=branch_name)] 76 branch_name=branch_name)]
76 c.total_cs = len(collection) 77 c.total_cs = len(collection)
77 else: 78 else:
78 collection = list(c.rhodecode_repo) 79 collection = c.rhodecode_repo
79 c.total_cs = len(c.rhodecode_repo) 80 c.total_cs = len(c.rhodecode_repo)
80
81 81
82 c.pagination = RepoPage(collection, page=p, item_count=c.total_cs, 82 c.pagination = RepoPage(collection, page=p, item_count=c.total_cs,
83 items_per_page=c.size, branch=branch_name) 83 items_per_page=c.size, branch=branch_name)
84 collection = list(c.pagination)
85 page_revisions = [x.raw_id for x in collection]
86 c.comments = c.rhodecode_db_repo.comments(page_revisions)
87
84 except (RepositoryError, ChangesetDoesNotExistError, Exception), e: 88 except (RepositoryError, ChangesetDoesNotExistError, Exception), e:
85 log.error(traceback.format_exc()) 89 log.error(traceback.format_exc())
86 h.flash(str(e), category='warning') 90 h.flash(str(e), category='warning')
87 return redirect(url('home')) 91 return redirect(url('home'))
88 92
89 self._graph(c.rhodecode_repo, collection, c.total_cs, c.size, p) 93 self._graph(c.rhodecode_repo, collection, c.total_cs, c.size, p)
90 94
91 c.branch_name = branch_name 95 c.branch_name = branch_name
92 c.branch_filters = [('',_('All Branches'))] + \ 96 c.branch_filters = [('', _('All Branches'))] + \
93 [(k,k) for k in c.rhodecode_repo.branches.keys()] 97 [(k, k) for k in c.rhodecode_repo.branches.keys()]
94
95 98
96 return render('changelog/changelog.html') 99 return render('changelog/changelog.html')
97 100
98 def changelog_details(self, cs): 101 def changelog_details(self, cs):
99 if request.environ.get('HTTP_X_PARTIAL_XHR'): 102 if request.environ.get('HTTP_X_PARTIAL_XHR'):
110 """ 113 """
111 if not collection: 114 if not collection:
112 c.jsdata = json.dumps([]) 115 c.jsdata = json.dumps([])
113 return 116 return
114 117
115 revcount = min(repo_size, size)
116 offset = 1 if p == 1 else ((p - 1) * revcount + 1)
117 try:
118 rev_end = collection.index(collection[(-1 * offset)])
119 except IndexError:
120 rev_end = collection.index(collection[-1])
121 rev_start = max(0, rev_end - revcount)
122
123 data = [] 118 data = []
124 rev_end += 1 119 revs = [x.revision for x in collection]
125 120
126 if repo.alias == 'git': 121 if repo.alias == 'git':
127 for _ in xrange(rev_start, rev_end): 122 for _ in revs:
128 vtx = [0, 1] 123 vtx = [0, 1]
129 edges = [[0, 0, 1]] 124 edges = [[0, 0, 1]]
130 data.append(['', vtx, edges]) 125 data.append(['', vtx, edges])
131 126
132 elif repo.alias == 'hg': 127 elif repo.alias == 'hg':
133 revs = list(reversed(xrange(rev_start, rev_end)))
134 c.dag = graphmod.colored(graphmod.dagwalker(repo._repo, revs)) 128 c.dag = graphmod.colored(graphmod.dagwalker(repo._repo, revs))
135 for (id, type, ctx, vtx, edges) in c.dag: 129 for (id, type, ctx, vtx, edges) in c.dag:
136 if type != graphmod.CHANGESET: 130 if type != graphmod.CHANGESET:
137 continue 131 continue
138 data.append(['', vtx, edges]) 132 data.append(['', vtx, edges])