aboutsummaryrefslogtreecommitdiff
path: root/web
diff options
context:
space:
mode:
authorRobin H. Johnson <robbat2@gentoo.org>2007-11-10 13:04:32 +0000
committerRobin H. Johnson <robbat2@gentoo.org>2007-11-10 13:04:32 +0000
commit162319718f8d3d3214320b75261744a606d294f5 (patch)
tree0ea3513db23cd837ae8de7cda943bed347545bb1 /web
parentRemove the pickle testing and workaround now that it is fixed. (diff)
downloadpackages-162319718f8d3d3214320b75261744a606d294f5.tar.gz
packages-162319718f8d3d3214320b75261744a606d294f5.tar.bz2
packages-162319718f8d3d3214320b75261744a606d294f5.zip
Factor out some duplicate MC code.
Diffstat (limited to 'web')
-rw-r--r--web/model.py45
1 files changed, 18 insertions, 27 deletions
diff --git a/web/model.py b/web/model.py
index 3360f66..fc0634c 100644
--- a/web/model.py
+++ b/web/model.py
@@ -194,6 +194,16 @@ class PackageDB(object):
s = spacematch.sub(' ', s)
self.sql[k] = s
#sql = FrozenDict(sql)
+
+ def _mc_wrap(self, key, func, **kwopts):
+ obj = None
+ if self.mc:
+ obj = self.mc.get(key)
+ if not obj:
+ obj = func()
+ if self.mc and obj:
+ self.mc.set(key, obj, **kwopts)
+ return obj
sql['SELECT_get_latest_timestamp'] = """
SELECT mtime
@@ -466,23 +476,10 @@ class PackageDB(object):
def get_package_details(self, cat, pn):
"""get package details"""
-
- cp = 'pkg_details_%s/%s' % (cat, pn)
- package_details = None
- if self.mc:
- package_details = self.mc.get(cp)
- if not package_details:
- package_details = self._get_package_details(cat, pn)
- #print '%r' % (package_details, )
- if self.mc and package_details:
- self.mc.set(cp, package_details, time=300)
- if 'atom' in package_details and \
- isinstance(package_details['atom'], str):
- try:
- package_details['atom'] = CPV(package_details['atom'])
- except AttributeError:
- print 'atom=%r' % (package_details['atom'],)
- return package_details
+ key = 'pkg_details_%s/%s' % (cat, pn)
+ def f():
+ return self._get_package_details(cat, pn)
+ return self._mc_wrap(key, f, time=300)
sql['SELECT_get_package_details_metadata'] = """
SELECT license, homepage, description, changelog
@@ -539,16 +536,10 @@ class PackageDB(object):
def get_package_keywords(self, query):
"""return cpv keywords"""
-
- cp = 'pkg_keywords_%s' % (query, )
- package_keywords = None
- if self.mc:
- package_keywords = self.mc.get(cp)
- if not package_keywords:
- package_keywords = self._get_package_keywords(query)
- if self.mc and package_keywords:
- self.mc.set(cp, package_keywords, time=300)
- return package_keywords
+ key = 'pkg_keywords_%s' % (query, )
+ def f():
+ return self._get_package_keywords(query)
+ return self._mc_wrap(key, f, time=300)
sql['SELECT_get_package_keywords_cat_pn'] = """
SELECT __CPV__, arches.arch, mode