From 1b1b516bd823d807ea81e62fe14fc92c18d0b89d Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Sun, 20 Jan 2013 14:59:30 -0600 Subject: 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 --- main/models.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'main') 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 -- cgit v1.2.3-24-g4f1b