diff options
author | Dan McGee <dan@archlinux.org> | 2011-11-04 04:46:36 +0100 |
---|---|---|
committer | Dan McGee <dan@archlinux.org> | 2011-11-04 05:04:16 +0100 |
commit | 19c2841f20653fd3c59f73fdb16f7f7b1ea15434 (patch) | |
tree | a15544c4cf2049e1c1c7cb47ecce645cefeff9bd /main | |
parent | 278d74b1d12568d4c9b6d5533e57e820d038ae64 (diff) | |
download | archweb-19c2841f20653fd3c59f73fdb16f7f7b1ea15434.tar.gz archweb-19c2841f20653fd3c59f73fdb16f7f7b1ea15434.tar.xz |
Add new attach_maintainers() utility method
This allows us to alleviate the N+1 query problem when we want
maintainer data for a queryset of packages. We use it on signoffs here;
we should also be able to apply this to the todolist section where this
problem has existed for some time.
Signed-off-by: Dan McGee <dan@archlinux.org>
Diffstat (limited to 'main')
-rw-r--r-- | main/models.py | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/main/models.py b/main/models.py index 972b098..db456c2 100644 --- a/main/models.py +++ b/main/models.py @@ -206,11 +206,19 @@ class Package(models.Model): def is_signed(self): return bool(self.pgp_signature) + _maintainers = None + @property def maintainers(self): - return User.objects.filter( - package_relations__pkgbase=self.pkgbase, - package_relations__type=PackageRelation.MAINTAINER) + if self._maintainers is None: + self._maintainers = User.objects.filter( + package_relations__pkgbase=self.pkgbase, + package_relations__type=PackageRelation.MAINTAINER) + return self._maintainers + + @maintainers.setter + def maintainers(self, maintainers): + self._maintainers = maintainers @cache_function(300) def applicable_arches(self): |