summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2010-06-21 08:00:18 +0200
committerDan McGee <dan@archlinux.org>2010-06-21 08:00:18 +0200
commit4c96b53f2ed9551028457ad6e0b26692c3cf385b (patch)
treef207d6e3c9e0c6b8b2ad5f4c122662f1a332d6c3
parentda9a1ecbf826c29b7bceb17b9f2d5a7c5f648e3b (diff)
downloadarchweb-4c96b53f2ed9551028457ad6e0b26692c3cf385b.tar.gz
archweb-4c96b53f2ed9551028457ad6e0b26692c3cf385b.tar.xz
Cache results of get_depends() and get_requiredby()
Do it in our actual cache rather than an object-level, single request cache. 300 seconds is good enough resolution to have this data right; if it is updated everyone will see the results 5 minutes late at the most. Signed-off-by: Dan McGee <dan@archlinux.org>
-rw-r--r--main/models.py8
1 files changed, 3 insertions, 5 deletions
diff --git a/main/models.py b/main/models.py
index 793407e..208ea1a 100644
--- a/main/models.py
+++ b/main/models.py
@@ -3,6 +3,7 @@ from django.db.models import Q
from django.contrib.auth.models import User
from django.contrib.sites.models import Site
+from main.utils import cache_function
from packages.models import PackageRelation
###########################
@@ -216,6 +217,7 @@ class Package(models.Model):
def approved_for_signoff(self):
return len(self.signoffs) >= 2
+ @cache_function(300)
def get_requiredby(self):
"""
Returns a list of package objects.
@@ -225,16 +227,13 @@ class Package(models.Model):
arch__name__in=(self.arch.name, 'any')).distinct()
return requiredby.order_by('pkgname')
+ @cache_function(300)
def get_depends(self):
"""
Returns a list of dicts. Each dict contains ('pkg' and 'dep').
If it represents a found package both vars will be available;
else pkg will be None if it is a 'virtual' dependency.
"""
- # object level cache. Doesn't last long, but helps for items rendered
- # twice in the same template.
- 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'):
@@ -259,7 +258,6 @@ class Package(models.Model):
if len(pkgs) > 0:
pkg = pkgs[0]
deps.append({'dep': dep, 'pkg': pkg})
- self.deps_cache = deps
return deps
def base_package(self):