From 23ef118ac129e17d251634d2ef3c88c6d74279e3 Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Sat, 19 Jan 2013 10:37:14 -0600 Subject: 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 --- public/views.py | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) (limited to 'public') diff --git a/public/views.py b/public/views.py index 3c823c9..22cb875 100644 --- a/public/views.py +++ b/public/views.py @@ -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) -- cgit v1.2.3-24-g4f1b