From 4c96b53f2ed9551028457ad6e0b26692c3cf385b Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Mon, 21 Jun 2010 01:00:18 -0500 Subject: 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 --- main/models.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/main/models.py b/main/models.py index 793407e9..208ea1a7 100644 --- a/main/models.py +++ b/main/models.py @@ -3,6 +3,7 @@ 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 @@ def signoffs(self): 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 @@ def get_requiredby(self): 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 @@ def get_depends(self): if len(pkgs) > 0: pkg = pkgs[0] deps.append({'dep': dep, 'pkg': pkg}) - self.deps_cache = deps return deps def base_package(self): -- cgit v1.2.3-54-g00ecf