summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2013-01-20 21:59:30 +0100
committerDan McGee <dan@archlinux.org>2013-01-20 22:01:13 +0100
commit1b1b516bd823d807ea81e62fe14fc92c18d0b89d (patch)
treedc5360125caaa5a7a483a750b3e678012f4d757d
parentdd8e94f69783365160bcbfda61a9bebea5a71324 (diff)
downloadarchweb-1b1b516bd.tar.gz
archweb-1b1b516bd.tar.xz
Query performance enhancements in get_requiredby()
For packages with particularly long lists of provides (e.g. perl), the query was getting a bit out of control with the list of names passed in. However, changing it to simply do a subquery resulted in some really poor planning by PostgreSQL. Doing this as a custom 'WHERE' clause utilizing the 'UNION ALL' SQL operator works very well. Signed-off-by: Dan McGee <dan@archlinux.org>
-rw-r--r--main/models.py11
1 files changed, 6 insertions, 5 deletions
diff --git a/main/models.py b/main/models.py
index 7155d36..88f0ecd 100644
--- a/main/models.py
+++ b/main/models.py
@@ -190,12 +190,13 @@ class Package(models.Model):
category as this package if that check makes sense.
"""
from packages.models import Depend
- provides = self.provides.all()
- provide_names = {provide.name for provide in provides}
- provide_names.add(self.pkgname)
+ name_clause = '''packages_depend.name IN (
+ SELECT %s UNION ALL
+ SELECT z.name FROM packages_provision z WHERE z.pkg_id = %s
+ )'''
requiredby = Depend.objects.select_related('pkg',
- 'pkg__arch', 'pkg__repo').filter(
- name__in=provide_names).order_by(
+ 'pkg__arch', 'pkg__repo').extra(
+ where=[name_clause], params=[self.pkgname, self.id]).order_by(
'pkg__pkgname', 'pkg__arch__name', 'pkg__repo__name')
if not self.arch.agnostic:
# make sure we match architectures if possible