From cba22a378b48f1a4f185a56a21f39483595cf8a6 Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Fri, 18 Jan 2013 20:01:22 -0600 Subject: Don't pull and sort mirror URLs unless we have to On the download page, the explicit sorted() call was forcing evaluation of the Django queryset, even if we never actually needed the results because the template fragment was cached. Wrap it all in a callable function which looks the same to the template, but saves us the cost of evaluation every single page view. Signed-off-by: Dan McGee --- public/views.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'public') diff --git a/public/views.py b/public/views.py index e15f5b8..3c823c9 100644 --- a/public/views.py +++ b/public/views.py @@ -82,11 +82,16 @@ def download(request): release = Release.objects.filter(available=True).latest() except Release.DoesNotExist: release = None - mirror_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') - mirror_urls = sorted(mirror_urls, key=sort_by) + + 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, -- cgit v1.2.3-24-g4f1b