Mercurial > kallithea
annotate pylons_app/controllers/changelog.py @ 245:a83a1799480c
Reimplemented way of caching repos list, hg model now get's repos objects right from cached dict, this way we skipp creating instances of MercurialRepository and gain performance. Some import cleanup
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Thu, 03 Jun 2010 00:04:48 +0200 |
parents | 7a97f0b100cd |
children | 3782a6d698af |
rev | line source |
---|---|
192
f191f99f59c9
full changelog caching, secured changelog with LoginRequired, some minor changes in graph
Marcin Kuzminski <marcin@python-works.com>
parents:
142
diff
changeset
|
1 from mercurial.graphmod import revisions as graph_rev, colored, CHANGESET |
f191f99f59c9
full changelog caching, secured changelog with LoginRequired, some minor changes in graph
Marcin Kuzminski <marcin@python-works.com>
parents:
142
diff
changeset
|
2 from mercurial.node import short |
245
a83a1799480c
Reimplemented way of caching repos list, hg model now get's repos objects right from cached dict, this way we skipp creating instances of MercurialRepository and gain performance. Some import cleanup
Marcin Kuzminski <marcin@python-works.com>
parents:
213
diff
changeset
|
3 from pylons import request, session, tmpl_context as c |
192
f191f99f59c9
full changelog caching, secured changelog with LoginRequired, some minor changes in graph
Marcin Kuzminski <marcin@python-works.com>
parents:
142
diff
changeset
|
4 from pylons_app.lib.auth import LoginRequired |
245
a83a1799480c
Reimplemented way of caching repos list, hg model now get's repos objects right from cached dict, this way we skipp creating instances of MercurialRepository and gain performance. Some import cleanup
Marcin Kuzminski <marcin@python-works.com>
parents:
213
diff
changeset
|
5 from pylons_app.lib.base import BaseController, render |
192
f191f99f59c9
full changelog caching, secured changelog with LoginRequired, some minor changes in graph
Marcin Kuzminski <marcin@python-works.com>
parents:
142
diff
changeset
|
6 from pylons_app.lib.filters import age as _age, person |
245
a83a1799480c
Reimplemented way of caching repos list, hg model now get's repos objects right from cached dict, this way we skipp creating instances of MercurialRepository and gain performance. Some import cleanup
Marcin Kuzminski <marcin@python-works.com>
parents:
213
diff
changeset
|
7 from pylons_app.model.hg_model import _full_changelog_cached |
192
f191f99f59c9
full changelog caching, secured changelog with LoginRequired, some minor changes in graph
Marcin Kuzminski <marcin@python-works.com>
parents:
142
diff
changeset
|
8 from simplejson import dumps |
f191f99f59c9
full changelog caching, secured changelog with LoginRequired, some minor changes in graph
Marcin Kuzminski <marcin@python-works.com>
parents:
142
diff
changeset
|
9 from webhelpers.paginate import Page |
f191f99f59c9
full changelog caching, secured changelog with LoginRequired, some minor changes in graph
Marcin Kuzminski <marcin@python-works.com>
parents:
142
diff
changeset
|
10 import logging |
196
568f95056716
moved all cache function out to Base Controller for easier maintainance
Marcin Kuzminski <marcin@python-works.com>
parents:
192
diff
changeset
|
11 log = logging.getLogger(__name__) |
93
aec4c0071cb3
added empty controllers for branches tags files graph, routing and test for them
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
12 |
aec4c0071cb3
added empty controllers for branches tags files graph, routing and test for them
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
13 class ChangelogController(BaseController): |
192
f191f99f59c9
full changelog caching, secured changelog with LoginRequired, some minor changes in graph
Marcin Kuzminski <marcin@python-works.com>
parents:
142
diff
changeset
|
14 |
f191f99f59c9
full changelog caching, secured changelog with LoginRequired, some minor changes in graph
Marcin Kuzminski <marcin@python-works.com>
parents:
142
diff
changeset
|
15 @LoginRequired() |
93
aec4c0071cb3
added empty controllers for branches tags files graph, routing and test for them
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
16 def __before__(self): |
192
f191f99f59c9
full changelog caching, secured changelog with LoginRequired, some minor changes in graph
Marcin Kuzminski <marcin@python-works.com>
parents:
142
diff
changeset
|
17 super(ChangelogController, self).__before__() |
f191f99f59c9
full changelog caching, secured changelog with LoginRequired, some minor changes in graph
Marcin Kuzminski <marcin@python-works.com>
parents:
142
diff
changeset
|
18 |
93
aec4c0071cb3
added empty controllers for branches tags files graph, routing and test for them
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
19 def index(self): |
213 | 20 limit = 100 |
21 default = 20 | |
192
f191f99f59c9
full changelog caching, secured changelog with LoginRequired, some minor changes in graph
Marcin Kuzminski <marcin@python-works.com>
parents:
142
diff
changeset
|
22 if request.params.get('size'): |
211
a3a7c3e03b76
version bump. Bugfix when changelog parameter was not an int. Added limit for 100 changelogs to view at once.
Marcin Kuzminski <marcin@python-works.com>
parents:
196
diff
changeset
|
23 try: |
a3a7c3e03b76
version bump. Bugfix when changelog parameter was not an int. Added limit for 100 changelogs to view at once.
Marcin Kuzminski <marcin@python-works.com>
parents:
196
diff
changeset
|
24 int_size = int(request.params.get('size')) |
a3a7c3e03b76
version bump. Bugfix when changelog parameter was not an int. Added limit for 100 changelogs to view at once.
Marcin Kuzminski <marcin@python-works.com>
parents:
196
diff
changeset
|
25 except ValueError: |
a3a7c3e03b76
version bump. Bugfix when changelog parameter was not an int. Added limit for 100 changelogs to view at once.
Marcin Kuzminski <marcin@python-works.com>
parents:
196
diff
changeset
|
26 int_size = default |
a3a7c3e03b76
version bump. Bugfix when changelog parameter was not an int. Added limit for 100 changelogs to view at once.
Marcin Kuzminski <marcin@python-works.com>
parents:
196
diff
changeset
|
27 int_size = int_size if int_size <= limit else limit |
a3a7c3e03b76
version bump. Bugfix when changelog parameter was not an int. Added limit for 100 changelogs to view at once.
Marcin Kuzminski <marcin@python-works.com>
parents:
196
diff
changeset
|
28 c.size = int_size |
192
f191f99f59c9
full changelog caching, secured changelog with LoginRequired, some minor changes in graph
Marcin Kuzminski <marcin@python-works.com>
parents:
142
diff
changeset
|
29 session['changelog_size'] = c.size |
f191f99f59c9
full changelog caching, secured changelog with LoginRequired, some minor changes in graph
Marcin Kuzminski <marcin@python-works.com>
parents:
142
diff
changeset
|
30 session.save() |
142
f7218849798a
Changeg graph to changelog, and changelog to shortlog
Marcin Kuzminski <marcin@python-works.com>
parents:
127
diff
changeset
|
31 else: |
211
a3a7c3e03b76
version bump. Bugfix when changelog parameter was not an int. Added limit for 100 changelogs to view at once.
Marcin Kuzminski <marcin@python-works.com>
parents:
196
diff
changeset
|
32 c.size = session.get('changelog_size', default) |
192
f191f99f59c9
full changelog caching, secured changelog with LoginRequired, some minor changes in graph
Marcin Kuzminski <marcin@python-works.com>
parents:
142
diff
changeset
|
33 |
f191f99f59c9
full changelog caching, secured changelog with LoginRequired, some minor changes in graph
Marcin Kuzminski <marcin@python-works.com>
parents:
142
diff
changeset
|
34 changesets = _full_changelog_cached(c.repo_name) |
f191f99f59c9
full changelog caching, secured changelog with LoginRequired, some minor changes in graph
Marcin Kuzminski <marcin@python-works.com>
parents:
142
diff
changeset
|
35 |
f191f99f59c9
full changelog caching, secured changelog with LoginRequired, some minor changes in graph
Marcin Kuzminski <marcin@python-works.com>
parents:
142
diff
changeset
|
36 p = int(request.params.get('page', 1)) |
f191f99f59c9
full changelog caching, secured changelog with LoginRequired, some minor changes in graph
Marcin Kuzminski <marcin@python-works.com>
parents:
142
diff
changeset
|
37 c.pagination = Page(changesets, page=p, item_count=len(changesets), |
f191f99f59c9
full changelog caching, secured changelog with LoginRequired, some minor changes in graph
Marcin Kuzminski <marcin@python-works.com>
parents:
142
diff
changeset
|
38 items_per_page=c.size) |
f191f99f59c9
full changelog caching, secured changelog with LoginRequired, some minor changes in graph
Marcin Kuzminski <marcin@python-works.com>
parents:
142
diff
changeset
|
39 |
f191f99f59c9
full changelog caching, secured changelog with LoginRequired, some minor changes in graph
Marcin Kuzminski <marcin@python-works.com>
parents:
142
diff
changeset
|
40 #self._graph(c.repo, c.size,p) |
142
f7218849798a
Changeg graph to changelog, and changelog to shortlog
Marcin Kuzminski <marcin@python-works.com>
parents:
127
diff
changeset
|
41 |
f7218849798a
Changeg graph to changelog, and changelog to shortlog
Marcin Kuzminski <marcin@python-works.com>
parents:
127
diff
changeset
|
42 return render('changelog/changelog.html') |
f7218849798a
Changeg graph to changelog, and changelog to shortlog
Marcin Kuzminski <marcin@python-works.com>
parents:
127
diff
changeset
|
43 |
f7218849798a
Changeg graph to changelog, and changelog to shortlog
Marcin Kuzminski <marcin@python-works.com>
parents:
127
diff
changeset
|
44 |
192
f191f99f59c9
full changelog caching, secured changelog with LoginRequired, some minor changes in graph
Marcin Kuzminski <marcin@python-works.com>
parents:
142
diff
changeset
|
45 def _graph(self, repo, size, p): |
142
f7218849798a
Changeg graph to changelog, and changelog to shortlog
Marcin Kuzminski <marcin@python-works.com>
parents:
127
diff
changeset
|
46 revcount = size |
f7218849798a
Changeg graph to changelog, and changelog to shortlog
Marcin Kuzminski <marcin@python-works.com>
parents:
127
diff
changeset
|
47 if not repo.revisions:return dumps([]), 0 |
f7218849798a
Changeg graph to changelog, and changelog to shortlog
Marcin Kuzminski <marcin@python-works.com>
parents:
127
diff
changeset
|
48 |
f7218849798a
Changeg graph to changelog, and changelog to shortlog
Marcin Kuzminski <marcin@python-works.com>
parents:
127
diff
changeset
|
49 max_rev = repo.revisions[-1] |
f7218849798a
Changeg graph to changelog, and changelog to shortlog
Marcin Kuzminski <marcin@python-works.com>
parents:
127
diff
changeset
|
50 offset = 1 if p == 1 else ((p - 1) * revcount) |
f7218849798a
Changeg graph to changelog, and changelog to shortlog
Marcin Kuzminski <marcin@python-works.com>
parents:
127
diff
changeset
|
51 rev_start = repo.revisions[(-1 * offset)] |
192
f191f99f59c9
full changelog caching, secured changelog with LoginRequired, some minor changes in graph
Marcin Kuzminski <marcin@python-works.com>
parents:
142
diff
changeset
|
52 c.bg_height = 120 |
142
f7218849798a
Changeg graph to changelog, and changelog to shortlog
Marcin Kuzminski <marcin@python-works.com>
parents:
127
diff
changeset
|
53 |
f7218849798a
Changeg graph to changelog, and changelog to shortlog
Marcin Kuzminski <marcin@python-works.com>
parents:
127
diff
changeset
|
54 revcount = min(max_rev, revcount) |
f7218849798a
Changeg graph to changelog, and changelog to shortlog
Marcin Kuzminski <marcin@python-works.com>
parents:
127
diff
changeset
|
55 rev_end = max(0, rev_start - revcount) |
f7218849798a
Changeg graph to changelog, and changelog to shortlog
Marcin Kuzminski <marcin@python-works.com>
parents:
127
diff
changeset
|
56 dag = graph_rev(repo.repo, rev_start, rev_end) |
192
f191f99f59c9
full changelog caching, secured changelog with LoginRequired, some minor changes in graph
Marcin Kuzminski <marcin@python-works.com>
parents:
142
diff
changeset
|
57 |
f191f99f59c9
full changelog caching, secured changelog with LoginRequired, some minor changes in graph
Marcin Kuzminski <marcin@python-works.com>
parents:
142
diff
changeset
|
58 c.dag = tree = list(colored(dag)) |
f191f99f59c9
full changelog caching, secured changelog with LoginRequired, some minor changes in graph
Marcin Kuzminski <marcin@python-works.com>
parents:
142
diff
changeset
|
59 canvasheight = (len(tree) + 1) * c.bg_height - 27 |
142
f7218849798a
Changeg graph to changelog, and changelog to shortlog
Marcin Kuzminski <marcin@python-works.com>
parents:
127
diff
changeset
|
60 data = [] |
f7218849798a
Changeg graph to changelog, and changelog to shortlog
Marcin Kuzminski <marcin@python-works.com>
parents:
127
diff
changeset
|
61 for (id, type, ctx, vtx, edges) in tree: |
f7218849798a
Changeg graph to changelog, and changelog to shortlog
Marcin Kuzminski <marcin@python-works.com>
parents:
127
diff
changeset
|
62 if type != CHANGESET: |
f7218849798a
Changeg graph to changelog, and changelog to shortlog
Marcin Kuzminski <marcin@python-works.com>
parents:
127
diff
changeset
|
63 continue |
f7218849798a
Changeg graph to changelog, and changelog to shortlog
Marcin Kuzminski <marcin@python-works.com>
parents:
127
diff
changeset
|
64 node = short(ctx.node()) |
f7218849798a
Changeg graph to changelog, and changelog to shortlog
Marcin Kuzminski <marcin@python-works.com>
parents:
127
diff
changeset
|
65 age = _age(ctx.date()) |
f7218849798a
Changeg graph to changelog, and changelog to shortlog
Marcin Kuzminski <marcin@python-works.com>
parents:
127
diff
changeset
|
66 desc = ctx.description() |
f7218849798a
Changeg graph to changelog, and changelog to shortlog
Marcin Kuzminski <marcin@python-works.com>
parents:
127
diff
changeset
|
67 user = person(ctx.user()) |
f7218849798a
Changeg graph to changelog, and changelog to shortlog
Marcin Kuzminski <marcin@python-works.com>
parents:
127
diff
changeset
|
68 branch = ctx.branch() |
f7218849798a
Changeg graph to changelog, and changelog to shortlog
Marcin Kuzminski <marcin@python-works.com>
parents:
127
diff
changeset
|
69 branch = branch, repo.repo.branchtags().get(branch) == ctx.node() |
f7218849798a
Changeg graph to changelog, and changelog to shortlog
Marcin Kuzminski <marcin@python-works.com>
parents:
127
diff
changeset
|
70 data.append((node, vtx, edges, desc, user, age, branch, ctx.tags())) |
f7218849798a
Changeg graph to changelog, and changelog to shortlog
Marcin Kuzminski <marcin@python-works.com>
parents:
127
diff
changeset
|
71 |
192
f191f99f59c9
full changelog caching, secured changelog with LoginRequired, some minor changes in graph
Marcin Kuzminski <marcin@python-works.com>
parents:
142
diff
changeset
|
72 c.jsdata = dumps(data) |
f191f99f59c9
full changelog caching, secured changelog with LoginRequired, some minor changes in graph
Marcin Kuzminski <marcin@python-works.com>
parents:
142
diff
changeset
|
73 c.canvasheight = canvasheight |
142
f7218849798a
Changeg graph to changelog, and changelog to shortlog
Marcin Kuzminski <marcin@python-works.com>
parents:
127
diff
changeset
|
74 |