diff options
author | Dan McGee <dan@archlinux.org> | 2013-01-20 19:43:33 +0100 |
---|---|---|
committer | Dan McGee <dan@archlinux.org> | 2013-02-09 23:20:38 +0100 |
commit | 271d1babbf8038e17d9dc5cfc3cd659463848400 (patch) | |
tree | bd563e669d8cf3cc730b223e366b9d07990e9e42 /packages | |
parent | 10462425f989dc74653179f0845978a6b5e30045 (diff) | |
download | archweb-271d1babbf8038e17d9dc5cfc3cd659463848400.tar.gz archweb-271d1babbf8038e17d9dc5cfc3cd659463848400.tar.xz |
Revert "Reduce query count when retrieving satisfiers and providers"
This reverts commit 20b64e42672d185821cc584dfa4b133ee259a144.
Django 1.5 fixed this issue and now parent objects are automatically
attached to their children when queries go through the related manager.
See "Caching of related model instances" in the release notes.
Signed-off-by: Dan McGee <dan@archlinux.org>
Diffstat (limited to 'packages')
-rw-r--r-- | packages/models.py | 20 |
1 files changed, 8 insertions, 12 deletions
diff --git a/packages/models.py b/packages/models.py index ff67788..7bcdc00 100644 --- a/packages/models.py +++ b/packages/models.py @@ -357,16 +357,14 @@ class RelatedToBase(models.Model): name = models.CharField(max_length=255, db_index=True) version = models.CharField(max_length=255, default='') - def get_best_satisfier(self, main_pkg=None): + def get_best_satisfier(self): '''Find a satisfier for this related package that best matches the given criteria. It will not search provisions, but will find packages named and matching repo characteristics if possible.''' - if main_pkg is None: - main_pkg = self.pkg pkgs = Package.objects.normal().filter(pkgname=self.name) - if not main_pkg.arch.agnostic: + if not self.pkg.arch.agnostic: # make sure we match architectures if possible - arches = main_pkg.applicable_arches() + arches = self.pkg.applicable_arches() pkgs = pkgs.filter(arch__in=arches) # if we have a comparison operation, make sure the packages we grab # actually satisfy the requirements @@ -386,27 +384,25 @@ class RelatedToBase(models.Model): pkg = pkgs[0] # prevents yet more DB queries, these lists should be short; # after each grab the best available in case we remove all entries - pkgs = [p for p in pkgs if p.repo.staging == main_pkg.repo.staging] + pkgs = [p for p in pkgs if p.repo.staging == self.pkg.repo.staging] if len(pkgs) > 0: pkg = pkgs[0] - pkgs = [p for p in pkgs if p.repo.testing == main_pkg.repo.testing] + pkgs = [p for p in pkgs if p.repo.testing == self.pkg.repo.testing] if len(pkgs) > 0: pkg = pkgs[0] return pkg - def get_providers(self, main_pkg=None): + def get_providers(self): '''Return providers of this related package. Does *not* include exact matches as it checks the Provision names only, use get_best_satisfier() instead for exact matches.''' - if main_pkg is None: - main_pkg = self.pkg pkgs = Package.objects.normal().filter( provides__name=self.name).order_by().distinct() - if not main_pkg.arch.agnostic: + if not self.pkg.arch.agnostic: # make sure we match architectures if possible - arches = main_pkg.applicable_arches() + arches = self.pkg.applicable_arches() pkgs = pkgs.filter(arch__in=arches) # If we have a comparison operation, make sure the packages we grab |