summaryrefslogtreecommitdiffstats
path: root/packages
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2013-01-12 23:47:20 +0100
committerDan McGee <dan@archlinux.org>2013-01-12 23:47:20 +0100
commit2bfdcec869ed4fceb11b9e0a2777fa53d46fb336 (patch)
tree54ff8371d77dbaf215e8d6e6e7d69f379f1361c8 /packages
parent6fe28b4206979a0db9c7d1f2f5f3a81c49d77951 (diff)
downloadarchweb-2bfdcec869ed4fceb11b9e0a2777fa53d46fb336.tar.gz
archweb-2bfdcec869ed4fceb11b9e0a2777fa53d46fb336.tar.xz
Make packages JSON search more performant
We were peppering the database with a bunch of queries here; using prefetch_related and attach_maintainers can cut down the count significantly. Signed-off-by: Dan McGee <dan@archlinux.org>
Diffstat (limited to 'packages')
-rw-r--r--packages/views/search.py8
1 files changed, 6 insertions, 2 deletions
diff --git a/packages/views/search.py b/packages/views/search.py
index f7b8ed1..f6e670d 100644
--- a/packages/views/search.py
+++ b/packages/views/search.py
@@ -12,7 +12,7 @@ from django.views.generic import ListView
from main.models import Package, Arch, Repo
from main.utils import make_choice
from ..models import PackageRelation
-from ..utils import PackageJSONEncoder
+from ..utils import attach_maintainers, PackageJSONEncoder
def coerce_limit_value(value):
@@ -185,10 +185,14 @@ def search_json(request):
form = PackageSearchForm(data=request.GET,
show_staging=request.user.is_authenticated())
if form.is_valid():
- packages = Package.objects.normal()
+ packages = Package.objects.select_related('arch', 'repo',
+ 'packager')
if not request.user.is_authenticated():
packages = packages.filter(repo__staging=False)
packages = parse_form(form, packages)[:limit]
+ packages = packages.prefetch_related('groups', 'licenses',
+ 'conflicts', 'provides', 'replaces', 'depends')
+ attach_maintainers(packages)
container['results'] = packages
container['valid'] = True