aboutsummaryrefslogtreecommitdiff
path: root/web
diff options
context:
space:
mode:
authorRobin H. Johnson <robbat2@gentoo.org>2009-06-03 07:08:27 +0000
committerRobin H. Johnson <robbat2@gentoo.org>2009-06-03 07:08:27 +0000
commit04a422fac77301e5874806410e12c015fea841ad (patch)
tree41e21e49b57bdc7e256467db5d77fc36e27703e8 /web
parentAdd more stats. (diff)
downloadpackages-04a422fac77301e5874806410e12c015fea841ad.tar.gz
packages-04a422fac77301e5874806410e12c015fea841ad.tar.bz2
packages-04a422fac77301e5874806410e12c015fea841ad.zip
Enable memcache for all get_ functions during rendering. Use a introspection callback trick to find the function name and save typing.
Diffstat (limited to 'web')
-rw-r--r--web/model.py127
1 files changed, 104 insertions, 23 deletions
diff --git a/web/model.py b/web/model.py
index dc1301e..99bbc27 100644
--- a/web/model.py
+++ b/web/model.py
@@ -18,6 +18,10 @@ from web.lib.links import viewcvs_link, \
# We use short variable names!
# pylint: disable-msg=C0103
+def caller_name():
+ """Return the name of the function that this was called from"""
+ return sys._getframe(1).f_code.co_name
+
def latest_per_day(cpvlist, daycount, pkgcount = 110):
"""generate list of sets with days and pv's as value"""
@@ -152,13 +156,20 @@ class PackageDB(object):
self.mc.set(key, obj, **kwopts)
return obj
+ def get_latest_timestamp(self):
+ """return modified cpvs"""
+ key = '%s' % (caller_name(), )
+ def f():
+ return self._get_latest_timestamp()
+ return self.mc_wrap(key, f, time=30)
+
sql['SELECT_get_latest_timestamp'] = """
SELECT mtime
FROM versions
ORDER BY mtime DESC
LIMIT 0,1
"""
- def get_latest_timestamp(self):
+ def _get_latest_timestamp(self):
"""return timestamp of latest modification"""
sql = self.sql['SELECT_get_latest_timestamp']
@@ -170,6 +181,13 @@ class PackageDB(object):
cursor.close()
return row
+ def get_latest_cpvs(self, limit=None):
+ """return modified cpvs"""
+ key = '%s_%s' % (caller_name(), limit)
+ def f():
+ return self._get_latest_cpvs(limit)
+ return self.mc_wrap(key, f, time=30)
+
sql['SELECT_get_latest_cpvs'] = """
SELECT __CPV__, versions.mtime
FROM versions
@@ -178,8 +196,8 @@ class PackageDB(object):
WHERE versions.mtime > ?
ORDER by versions.mtime DESC
LIMIT 0, ?"""
- def get_latest_cpvs(self, limit=None):
- """return modified cpvs"""
+ def _get_latest_cpvs(self, limit=None):
+ """return modified cpvs (uncached)"""
sql = self.sql['SELECT_get_latest_cpvs']
@@ -200,6 +218,13 @@ class PackageDB(object):
cursor.close()
return entries
+ def get_latest_cpvs_by_verbump(self, limit=None):
+ """return modified cpvs"""
+ key = '%s_%s' % (caller_name(), limit)
+ def f():
+ return self._get_latest_cpvs_by_verbump(limit)
+ return self.mc_wrap(key, f, time=30)
+
sql['SELECT_get_latest_cpvs_by_verbump'] = """
SELECT __CPV__, verbumps.mtime
FROM verbumps
@@ -210,8 +235,8 @@ class PackageDB(object):
WHERE verbumps.mtime > ?
ORDER by verbumps.mtime DESC
LIMIT 0, ?"""
- def get_latest_cpvs_by_verbump(self, limit=None):
- """return modified cpvs"""
+ def _get_latest_cpvs_by_verbump(self, limit=None):
+ """return modified cpvs (uncached)"""
# We cannot rely on the contents of ChangeLog here
# otherwise we could add this bit of magic:
# AND SUBSTR(metadata.changelog,1,1)='*'
@@ -233,6 +258,13 @@ class PackageDB(object):
entries = cursor.fetchall()
cursor.close()
return entries
+
+ def get_latest_cpvs_by_newpkg(self, limit=None):
+ """return modified cpvs"""
+ key = '%s_%s' % (caller_name(), limit)
+ def f():
+ return self._get_latest_cpvs_by_newpkg(limit)
+ return self.mc_wrap(key, f, time=30)
sql['SELECT_get_latest_cpvs_by_newpkg'] = """
SELECT __CPV__, verbumps.mtime
@@ -245,8 +277,8 @@ class PackageDB(object):
ORDER by verbumps.mtime DESC
LIMIT 0, ?
"""
- def get_latest_cpvs_by_newpkg(self, limit=None):
- """return modified cpvs"""
+ def _get_latest_cpvs_by_newpkg(self, limit=None):
+ """return modified cpvs (uncached)"""
# We cannot rely on the contents of ChangeLog here
# otherwise we could add this bit of magic:
# AND SUBSTR(metadata.changelog,1,1)='*'
@@ -270,6 +302,13 @@ class PackageDB(object):
cursor.close()
return entries
+ def get_latest_cpvs_by_pkgname(self, pkgname, limit=None):
+ """return modified cpvs"""
+ key = '%s_%s_%s' % (caller_name(), pkgname, limit)
+ def f():
+ return self._get_latest_cpvs_by_pkgname(pkgname, limit)
+ return self.mc_wrap(key, f, time=30)
+
sql['SELECT_get_latest_cpvs_by_pkgname'] = """
SELECT __CPV__, versions.mtime
FROM versions
@@ -279,8 +318,8 @@ class PackageDB(object):
ORDER by versions.mtime DESC
LIMIT 0, ?
"""
- def get_latest_cpvs_by_pkgname(self, pkgname, limit=None):
- """return modified cpvs"""
+ def _get_latest_cpvs_by_pkgname(self, pkgname, limit=None):
+ """return modified cpvs (uncached)"""
sql = self.sql['SELECT_get_latest_cpvs_by_pkgname']
if limit is None:
@@ -296,6 +335,13 @@ class PackageDB(object):
cursor.close()
return entries
+ def get_latest_cpvs_by_category(self, cat, limit=None):
+ """return modified cpvs"""
+ key = '%s_%s_%s' % (caller_name(), cat, limit)
+ def f():
+ return self._get_latest_cpvs_by_category(cat, limit)
+ return self.mc_wrap(key, f, time=30)
+
sql['SELECT_get_latest_cpvs_by_category'] = """
SELECT __CPV__, versions.mtime
FROM versions
@@ -305,8 +351,8 @@ class PackageDB(object):
ORDER by versions.mtime DESC
LIMIT 0, ?
"""
- def get_latest_cpvs_by_category(self, cat, limit=None):
- """return modified cpvs"""
+ def _get_latest_cpvs_by_category(self, cat, limit=None):
+ """return modified cpvs (uncached)"""
sql = self.sql['SELECT_get_latest_cpvs_by_category']
if limit is None:
@@ -322,6 +368,13 @@ class PackageDB(object):
cursor.close()
return entries
+ def get_latest_cpvs_by_category_pkgname(self, cat, pn, limit=None):
+ """return modified cpvs"""
+ key = '%s_%s/%s_%s' % (caller_name(), cat, pn, limit)
+ def f():
+ return self._get_latest_cpvs_by_category_pkgname(cat, pn, limit)
+ return self.mc_wrap(key, f, time=30)
+
sql['SELECT_get_latest_cpvs_by_category_pkgname'] = """
SELECT __CPV__, versions.mtime
FROM versions
@@ -331,8 +384,8 @@ class PackageDB(object):
ORDER by versions.mtime DESC
LIMIT 0, ?
"""
- def get_latest_cpvs_by_category_pkgname(self, cat, pn, limit=None):
- """return modified cpvs"""
+ def _get_latest_cpvs_by_category_pkgname(self, cat, pn, limit=None):
+ """return modified cpvs (uncached)"""
sql = self.sql['SELECT_get_latest_cpvs_by_category_pkgname']
if limit is None:
@@ -348,6 +401,13 @@ class PackageDB(object):
cursor.close()
return entries
+ def get_latest_cpvs_by_arch(self, arch, mode, limit=None):
+ """return modified cpvs limited by arch and mode"""
+ key = '%s_%s_%s_%s' % (caller_name(), arch, mode, limit)
+ def f():
+ return self._get_latest_cpvs_by_arch(arch, mode, limit)
+ return self.mc_wrap(key, f, time=30)
+
sql['SELECT_get_latest_cpvs_by_arch_mode'] = """
SELECT __CPV__, versions.mtime
FROM arches
@@ -370,8 +430,8 @@ class PackageDB(object):
ORDER by versions.mtime DESC
LIMIT 0, ?
"""
- def get_latest_cpvs_by_arch(self, arch, mode, limit=None):
- """return modified cpvs limited by arch and mode"""
+ def _get_latest_cpvs_by_arch(self, arch, mode, limit=None):
+ """return modified cpvs limited by arch and mode (uncached)"""
valid_modes = ['+', '~', 'M', 'M+', 'M~', '']
params = ()
@@ -400,6 +460,13 @@ class PackageDB(object):
def get_package_details_cpv(self, cpvstr):
"""get package details with versionfiltered keywords"""
+ key = '%s_%s' % (caller_name(), str(cpvstr))
+ def f():
+ return self._get_package_details_cpv(cpvstr)
+ return self.mc_wrap(key, f, time=30)
+
+ def _get_package_details_cpv(self, cpvstr):
+ """get package details with versionfiltered keywords (uncached)"""
atom = CPV(str(cpvstr))
(cat, pn) = (atom.category, atom.package)
@@ -438,10 +505,10 @@ class PackageDB(object):
def get_package_details(self, cat, pn):
"""get package details"""
- key = 'pkg_details_%s/%s' % (cat, pn)
+ key = '%s_%s/%s' % (caller_name(), cat, pn)
def f():
return self._get_package_details(cat, pn)
- return self.mc_wrap(key, f, time=300)
+ return self.mc_wrap(key, f, time=30)
sql['SELECT_get_package_details_metadata'] = """
SELECT license, homepage, description, changelog
@@ -498,10 +565,10 @@ class PackageDB(object):
def get_package_keywords(self, query):
"""return cpv keywords"""
- key = 'pkg_keywords_%s' % (query, )
+ key = '%s_%s' % (caller_name(), query, )
def f():
return self._get_package_keywords(query)
- return self.mc_wrap(key, f, time=300)
+ return self.mc_wrap(key, f, time=30)
sql['SELECT_get_package_keywords_cat_pn'] = """
SELECT __CPV__, arches.arch, mode
@@ -578,14 +645,21 @@ class PackageDB(object):
cursor.close()
return ret_list
+ def get_category_packages(self, cat):
+ """get a list of all packages for a category"""
+ key = '%s_%s' % (caller_name(), cat, )
+ def f():
+ return self._get_category_packages(cat)
+ return self.mc_wrap(key, f, time=30)
+
sql['SELECT_get_category_packages'] = """
SELECT __CP__, 0
FROM packages
JOIN categories USING (c)
WHERE category = ?
ORDER BY pn"""
- def get_category_packages(self, cat):
- """get a list of all packages for a category"""
+ def _get_category_packages(self, cat):
+ """get a list of all packages for a category (uncached)"""
sql = self.sql['SELECT_get_category_packages']
cursor = self.cursor()
@@ -594,6 +668,13 @@ class PackageDB(object):
cursor.close()
return entries
+ def get_category_list(self):
+ """get a list of all categories with their package and ebuild counts"""
+ key = '%s' % (caller_name(), )
+ def f():
+ return self._get_category_list()
+ return self.mc_wrap(key, f, time=30)
+
sql['SELECT_get_category_list'] = """
SELECT category, COUNT(DISTINCT cp), COUNT(DISTINCT cpv)
FROM categories
@@ -601,8 +682,8 @@ class PackageDB(object):
JOIN versions USING (cp)
GROUP BY c
ORDER BY category"""
- def get_category_list(self):
- """get a list of all categories with their package and ebuild counts"""
+ def _get_category_list(self):
+ """get a list of all categories with their package and ebuild counts (uncached)"""
sql = self.sql['SELECT_get_category_list']
cursor = self.cursor()