From 2bfdcec869ed4fceb11b9e0a2777fa53d46fb336 Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Sat, 12 Jan 2013 16:47:20 -0600 Subject: 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 --- packages/views/search.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'packages') 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 -- cgit v1.2.3-24-g4f1b