Permalink
Browse files

Fix branch menu slowness.

git-svn-id: http://rietveld.googlecode.com/svn/trunk@397 e30e9e8f-1b4c-0410-881d-6f13584adfe0
  • Loading branch information...
gvanrossum
gvanrossum committed Feb 19, 2009
1 parent bf75b59 commit 96dd7e0417363f60e88344091f9286c22f239b44
Showing with 16 additions and 4 deletions.
  1. +3 −0 codereview/models.py
  2. +13 −4 codereview/views.py
View
@@ -465,6 +465,9 @@ class Branch(db.Model):
"""A trunk, branch, or atag in a specific Subversion repository."""
repo = db.ReferenceProperty(Repository, required=True)
# Cache repo.name as repo_name, to speed up set_branch_choices()
# in views.IssueBaseForm.
repo_name = db.StringProperty()
category = db.StringProperty(required=True,
choices=('*trunk*', 'branch', 'tag'))
name = db.StringProperty(required=True)
View
@@ -127,13 +127,18 @@ class IssueBaseForm(forms.Form):
def set_branch_choices(self, base=None):
branches = models.Branch.gql('ORDER BY repo, category, name')
bound_field = self['branch']
choices = [('', '[See Base]')]
choices = []
default = None
for b in branches:
pair = (b.key(), '%s - %s - %s' % (b.repo.name, b.category, b.name))
if not b.repo_name:
b.repo_name = b.repo.name
b.put()
pair = (b.key(), '%s - %s - %s' % (b.repo_name, b.category, b.name))
choices.append(pair)
if default is None and (base is None or b.url == base):
default = b.key()
choices.sort(key=lambda pair: pair[1].lower())
choices.insert(0, ('', '[See Base]'))
bound_field.field.choices = choices
if default is not None:
self.initial['branch'] = default
@@ -2289,7 +2294,8 @@ def repo_new(request):
if not branch_url.endswith('/'):
branch_url += '/'
branch_url += 'trunk/'
branch = models.Branch(repo=repo, category='*trunk*', name='Trunk',
branch = models.Branch(repo=repo, repo_name=repo.name,
category='*trunk*', name='Trunk',
url=branch_url)
branch.put()
return HttpResponseRedirect('/repos')
@@ -2320,7 +2326,8 @@ def repo_init(request):
if (br.category, br.name, br.url) == (category, name, url):
break
else:
br = models.Branch(repo=python, category=category, name=name, url=url)
br = models.Branch(repo=python, repo_name='Python',
category=category, name=name, url=url)
br.put()
return HttpResponseRedirect('/repos')
@@ -2345,6 +2352,7 @@ def branch_new(request, repo_id):
errors['__all__'] = unicode(err)
if errors:
return respond(request, 'branch_new.html', {'form': form, 'repo': repo})
branch.repo_name = repo.name
branch.put()
return HttpResponseRedirect('/repos')
@@ -2369,6 +2377,7 @@ def branch_edit(request, branch_id):
if errors:
return respond(request, 'branch_edit.html',
{'branch': branch, 'form': form})
branch.repo_name = repo.name
branch.put()
return HttpResponseRedirect('/repos')

0 comments on commit 96dd7e0

Please sign in to comment.