From f58b354a037d2c46fd8db9320f8ba29c9e014436 Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Sun, 31 Jan 2010 15:19:12 -0600 Subject: Use select_related() to make a few more places more performant Especially when looking at packages, we always want the arch and repo. Another big hunk of changes deals with the very inefficient signoffs code. Signed-off-by: Dan McGee --- main/models.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'main') diff --git a/main/models.py b/main/models.py index 80033546..9e572cee 100644 --- a/main/models.py +++ b/main/models.py @@ -202,13 +202,18 @@ def get_absolute_url(self): @property def signoffs(self): - return Signoff.objects.filter( + if 'signoffs_cache' in dir(self): + if len(self.signoffs_cache) > 0: + print self.signoffs_cache + return self.signoffs_cache + self.signoffs_cache = list(Signoff.objects.filter( pkg=self, pkgver=self.pkgver, - pkgrel=self.pkgrel) + pkgrel=self.pkgrel)) + return self.signoffs_cache def approved_for_signoff(self): - return self.signoffs.count() >= 2 + return len(self.signoffs) >= 2 def get_requiredby(self): """ @@ -234,9 +239,10 @@ def get_depends(self): if 'deps_cache' in dir(self): return self.deps_cache deps = [] + # TODO: we can use list comprehension and an 'in' query to make this more effective for dep in self.packagedepend_set.order_by('depname'): # we only need depend on same-arch-packages - pkgs = Package.objects.filter( + pkgs = Package.objects.select_related('arch', 'repo').filter( Q(arch__name__iexact='any') | Q(arch=self.arch), pkgname=dep.depname) if len(pkgs) == 0: -- cgit v1.2.3-54-g00ecf