aboutsummaryrefslogtreecommitdiff
path: root/web
diff options
context:
space:
mode:
authorRobin H. Johnson <robbat2@gentoo.org>2007-11-11 01:05:33 +0000
committerRobin H. Johnson <robbat2@gentoo.org>2007-11-11 01:05:33 +0000
commitd9570c864c0bdb1f7b8cad08158053f1fca4e933 (patch)
tree470bab50ceb07dd7caa68149a59a79c81e0db44a /web
parentSplit up the code a bit more. (diff)
downloadpackages-d9570c864c0bdb1f7b8cad08158053f1fca4e933.tar.gz
packages-d9570c864c0bdb1f7b8cad08158053f1fca4e933.tar.bz2
packages-d9570c864c0bdb1f7b8cad08158053f1fca4e933.zip
Use memcache.
Diffstat (limited to 'web')
-rw-r--r--web/lib/filters.py112
1 files changed, 40 insertions, 72 deletions
diff --git a/web/lib/filters.py b/web/lib/filters.py
index 52d6ca6..4fa0cb4 100644
--- a/web/lib/filters.py
+++ b/web/lib/filters.py
@@ -35,18 +35,6 @@ def limit_arches(kwds):
arches = ConstData.exotic_arches
return arches
-cache_arches = {}
-cache_category = {}
-cache_category_package = {}
-cache_hardmasked = {}
-cache_latest_entry = {}
-cache_newpkgs = {}
-cache_package = {}
-cache_stable = {}
-cache_unfiltered = {}
-cache_unstable = {}
-cache_verbumps = {}
-
class EntryFilters(object):
"""Filter class for latest_entries list"""
@@ -56,12 +44,10 @@ class EntryFilters(object):
def category_filter(self, catname, use_latest=True, limit=None):
"""Skip packages not matching our category"""
- key = '%r%r%r' % (catname,use_latest,limit)
- if key in cache_category:
- return cache_category[key]
- ret = self._category_filter(catname, use_latest, limit)
- cache_category[key] = ret
- return ret
+ key = 'category_filter_%r%r%r' % (catname, use_latest, limit)
+ def f():
+ return self._category_filter(catname, use_latest, limit)
+ return self.package_source.mc_wrap(key, f, time=300)
def _category_filter(self, catname, use_latest=True, limit=None):
"""Skip packages not matching our category (uncached)"""
@@ -81,12 +67,10 @@ class EntryFilters(object):
def package_filter(self, pkgname, limit=None):
"""Skip packages not matching pkgname"""
- key = '%r%r' % (pkgname,limit)
- if key in cache_package:
- return cache_package[key]
- ret = self._package_filter(pkgname, limit)
- cache_package[key] = ret
- return ret
+ key = 'package_filter_%r%r' % (pkgname, limit)
+ def f():
+ return self._package_filter(pkgname, limit)
+ return self.package_source.mc_wrap(key, f, time=300)
def _package_filter(self, pkgname, limit=None):
"""Skip packages not matching pkgname (uncached)"""
@@ -96,12 +80,10 @@ class EntryFilters(object):
def category_package_filter(self, category, pkgname, limit=None):
"""Skip packages not matching pkgname and category"""
- key = '%r%r%r' % (category,pkgname,limit)
- if key in cache_category_package:
- return cache_category_package[key]
- ret = self._category_package_filter(category, pkgname, limit)
- cache_category_package[key] = ret
- return ret
+ key = 'category_package_filter_%r%r%r' % (category, pkgname, limit)
+ def f():
+ return self._category_package_filter(category, pkgname, limit)
+ return self.package_source.mc_wrap(key, f, time=300)
def _category_package_filter(self, category, pkgname, limit=None):
"""Skip packages not matching pkgname and category (uncached)"""
@@ -111,12 +93,10 @@ class EntryFilters(object):
def hardmasked_filter(self, arch, limit=None):
"""Filter packages by hardmasked for arch"""
- key = '%r%r' % (arch,limit)
- if key in cache_hardmasked:
- return cache_hardmasked[key]
- ret = self._hardmasked_filter(arch, limit)
- cache_hardmasked[key] = ret
- return ret
+ key = 'hardmasked_filter_%r%r' % (arch, limit)
+ def f():
+ return self._hardmasked_filter(arch, limit)
+ return self.package_source.mc_wrap(key, f, time=300)
def _hardmasked_filter(self, arch, limit=None):
"""Filter packages by hardmasked for arch (uncached)"""
@@ -124,12 +104,10 @@ class EntryFilters(object):
def stable_filter(self, arch, limit=None):
"""Filter packages by stable keyword for arch"""
- key = '%r%r' % (arch,limit)
- if key in cache_stable:
- return cache_stable[key]
- ret = self._stable_filter(arch, limit)
- cache_stable[key] = ret
- return ret
+ key = 'stable_filter_%r%r' % (arch, limit)
+ def f():
+ return self._stable_filter(arch, limit)
+ return self.package_source.mc_wrap(key, f, time=300)
def _stable_filter(self, arch, limit=None):
"""Filter packages by stable keyword for arch (uncached)"""
@@ -137,12 +115,10 @@ class EntryFilters(object):
def unstable_filter(self, arch, limit=None):
"""Filter packages by unstable keyword for arch"""
- key = '%r%r' % (arch,limit)
- if key in cache_unstable:
- return cache_unstable[key]
- ret = self._unstable_filter(arch, limit)
- cache_unstable[key] = ret
- return ret
+ key = 'unstable_filter_%r%r' % (arch, limit)
+ def f():
+ return self._unstable_filter(arch, limit)
+ return self.package_source.mc_wrap(key, f, time=300)
def _unstable_filter(self, arch, limit=None):
"""Filter packages by unstable keyword for arch (uncached)"""
@@ -150,12 +126,10 @@ class EntryFilters(object):
def arch_filter(self, arch, limit=None):
"""Filter packages by any keyword for arch"""
- key = '%r%r' % (arch,limit)
- if key in cache_arches:
- return cache_arches[key]
- ret = self._arch_filter(arch, limit)
- cache_arches[key] = ret
- return ret
+ key = 'arch_filter_%r%r' % (arch, limit)
+ def f():
+ return self._arch_filter(arch, limit)
+ return self.package_source.mc_wrap(key, f, time=300)
def _arch_filter(self, arch, limit=None):
"""Filter packages by any keyword for arch (uncached)"""
@@ -163,12 +137,10 @@ class EntryFilters(object):
def verbumps_filter(self, limit=None):
"""Filter packages to version bumps only"""
- key = '%r' % (limit)
- if key in cache_verbumps:
- return cache_verbumps[key]
- ret = self._verbumps_filter(limit)
- cache_verbumps[key] = ret
- return ret
+ key = 'verbumps_filter_%r' % (limit, )
+ def f():
+ return self._verbumps_filter(limit)
+ return self.package_source.mc_wrap(key, f, time=300)
def _verbumps_filter(self, limit=None):
"""Filter packages to version bumps only (uncached)"""
@@ -176,12 +148,10 @@ class EntryFilters(object):
def newpkgs_filter(self, limit=None):
"""Filter packages to new packages only"""
- key = '%r' % (limit)
- if key in cache_newpkgs:
- return cache_newpkgs[key]
- ret = self._newpkgs_filter(limit)
- cache_newpkgs[key] = ret
- return ret
+ key = 'newpkgs_filter_%r' % (limit, )
+ def f():
+ return self._newpkgs_filter(limit)
+ return self.package_source.mc_wrap(key, f, time=300)
def _newpkgs_filter(self, limit=None):
"""Filter packages to new packages only (uncached)"""
@@ -189,12 +159,10 @@ class EntryFilters(object):
def unfiltered(self, limit=None):
"""unfiltered list"""
- key = '%r' % (limit)
- if key in cache_unfiltered:
- return cache_unfiltered[key]
- ret = self._unfiltered(limit)
- cache_unfiltered[key] = ret
- return ret
+ key = 'unfiltered_%r' % (limit, )
+ def f():
+ return self._unfiltered(limit)
+ return self.package_source.mc_wrap(key, f, time=300)
def _unfiltered(self, limit=None):
"""unfiltered list"""