Don't redefine mirror_url function every call

If we pull this out and define it at the top level once, we save the
interpreter a fair amount of work.

Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
Dan McGee 2013-01-19 10:37:14 -06:00
parent 721f092e4a
commit 23ef118ac1

View File

@ -76,6 +76,16 @@ def donate(request):
return render(request, 'public/donate.html', context)
def _mirror_urls():
'''In order to ensure this is lazily evaluated since we can't do
sorting at the database level, make it a callable.'''
urls = MirrorUrl.objects.select_related('mirror').filter(
protocol__default=True,
mirror__public=True, mirror__active=True, mirror__isos=True)
sort_by = attrgetter('country.name', 'mirror.name')
return sorted(urls, key=sort_by)
@cache_control(max_age=300)
def download(request):
try:
@ -83,20 +93,11 @@ def download(request):
except Release.DoesNotExist:
release = None
def mirror_urls():
'''In order to ensure this is lazily evaluated since we can't do
sorting at the database level, make it a callable.'''
urls = MirrorUrl.objects.select_related('mirror').filter(
protocol__default=True,
mirror__public=True, mirror__active=True, mirror__isos=True)
sort_by = attrgetter('country.name', 'mirror.name')
return sorted(urls, key=sort_by)
context = {
'release': release,
'releng_iso_url': settings.ISO_LIST_URL,
'releng_pxeboot_url': settings.PXEBOOT_URL,
'mirror_urls': mirror_urls,
'mirror_urls': _mirror_urls,
}
return render(request, 'public/download.html', context)