summaryrefslogtreecommitdiff
path: root/packages
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2010-02-16 19:41:16 -0600
committerDan McGee <dan@archlinux.org>2010-02-16 19:43:08 -0600
commite732861961feca370d6472b5bd64242faaa2fab6 (patch)
tree7055b95b064b006e3b7daa8363bc22f82945a27c /packages
parentf3db1bb123ee4c61e7bb7e8a0c671d831a1ce990 (diff)
Make packages view much more efficient
The len() call was killing performance, especially in the default click-thru case where we show the packages list without any filtering (only sorting). Also use a well-placed select_related() to further drop the query count. As noted by the TODO, there is still more that can be done here to improve performance. Signed-off-by: Dan McGee <dan@archlinux.org>
Diffstat (limited to 'packages')
-rw-r--r--packages/views.py5
1 files changed, 3 insertions, 2 deletions
diff --git a/packages/views.py b/packages/views.py
index e828c263..487f20df 100644
--- a/packages/views.py
+++ b/packages/views.py
@@ -125,7 +125,7 @@ class PackageSearchForm(forms.Form):
def search(request, page=None):
current_query = '?'
limit=50
- packages = Package.objects.all()
+ packages = Package.objects.select_related('arch', 'repo', 'maintainer')
if request.GET:
# urlencode can't handle unicode. One fix for this is to call:
@@ -168,12 +168,13 @@ def search(request, page=None):
page_dict = {'search_form': form,
'current_query': current_query
}
- if len(packages) == 1:
+ if packages.count() == 1:
return HttpResponseRedirect(packages[0].get_absolute_url())
allowed_sort = ["arch", "repo", "pkgname", "maintainer", "last_update"]
allowed_sort += ["-" + s for s in allowed_sort]
sort = request.GET.get('sort', None)
+ # TODO: sorting by multiple fields makes using a DB index much harder
if sort in allowed_sort:
packages = packages.order_by(
request.GET['sort'], 'repo', 'arch', 'pkgname')