diff options
author | Dan McGee <dan@archlinux.org> | 2010-01-31 15:19:12 -0600 |
---|---|---|
committer | Dan McGee <dan@archlinux.org> | 2010-01-31 15:19:12 -0600 |
commit | f58b354a037d2c46fd8db9320f8ba29c9e014436 (patch) | |
tree | 05aaea7bcd1a055af9d873482a40b7ecdc44a082 /main | |
parent | e0eed01914752ee98d50aeab748f71b24df94dc6 (diff) |
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 <dan@archlinux.org>
Diffstat (limited to 'main')
-rw-r--r-- | main/models.py | 14 |
1 files changed, 10 insertions, 4 deletions
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 @@ class Package(models.Model): @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 @@ class Package(models.Model): 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: |