Use a subquery rather than two queries in attach_maintainers
Now that we are using a database that doesn't stink, it makes more sense to do all of the stuff we need to do down at the database level. This helps a lot when 500+ packages are in play at a given time, such as some of our larger rebuild todo lists. Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
parent
e9e1c07165
commit
2c958511c4
@ -6,6 +6,7 @@
|
|||||||
from django.core.serializers.json import DjangoJSONEncoder
|
from django.core.serializers.json import DjangoJSONEncoder
|
||||||
from django.db import connection
|
from django.db import connection
|
||||||
from django.db.models import Count, Max, F
|
from django.db.models import Count, Max, F
|
||||||
|
from django.db.models.query import QuerySet
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
|
|
||||||
from main.models import Package, PackageFile, Arch, Repo
|
from main.models import Package, PackageFile, Arch, Repo
|
||||||
@ -253,8 +254,11 @@ def attach_maintainers(packages):
|
|||||||
'''Given a queryset or something resembling it of package objects, find all
|
'''Given a queryset or something resembling it of package objects, find all
|
||||||
the maintainers and attach them to the packages to prevent N+1 query
|
the maintainers and attach them to the packages to prevent N+1 query
|
||||||
cascading.'''
|
cascading.'''
|
||||||
packages = list(packages)
|
if isinstance(packages, QuerySet):
|
||||||
pkgbases = {p.pkgbase for p in packages if p is not None}
|
pkgbases = packages.values('pkgbase')
|
||||||
|
else:
|
||||||
|
packages = list(packages)
|
||||||
|
pkgbases = {p.pkgbase for p in packages if p is not None}
|
||||||
rels = PackageRelation.objects.filter(type=PackageRelation.MAINTAINER,
|
rels = PackageRelation.objects.filter(type=PackageRelation.MAINTAINER,
|
||||||
pkgbase__in=pkgbases).values_list(
|
pkgbase__in=pkgbases).values_list(
|
||||||
'pkgbase', 'user_id').order_by().distinct()
|
'pkgbase', 'user_id').order_by().distinct()
|
||||||
|
Loading…
Reference in New Issue
Block a user