summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRaymond Mancy <rmancy@redhat.com>2011-01-03 19:26:20 +1000
committerBill Peck <bpeck@redhat.com>2011-01-03 20:24:49 -0500
commit11820f3e1919c6b54bc048bd136d6d3dadacb9fa (patch)
tree80780d39db2d1f8ff51217ca9b58349ec8ecf378
parent2945ec27a6550fc2926da24f8f4736e9245d3cfe (diff)
bz659804 - cache some results from sqla
-rw-r--r--Server/bkr/server/helpers.py15
-rw-r--r--Server/bkr/server/model.py10
2 files changed, 25 insertions, 0 deletions
diff --git a/Server/bkr/server/helpers.py b/Server/bkr/server/helpers.py
index 0e169c9..c2b4efd 100644
--- a/Server/bkr/server/helpers.py
+++ b/Server/bkr/server/helpers.py
@@ -32,6 +32,21 @@ def make_fake_link(name,id,text):
a.text = '%s ' % text
return a
+def cache(f):
+ the_cache = {}
+ def do_cache(*args):
+ args = tuple(args)
+ #Make sure we have different cache vals for args
+ args_to_hash = args + (f,)
+ cache = the_cache
+ try:
+ return cache[args_to_hash]
+ except KeyError:
+ result = f(*args)
+ the_cache[args_to_hash] = result
+ return result
+ return do_cache
+
def to_byte_string(encoding):
"""
encode the dict/array/string returned by generators
diff --git a/Server/bkr/server/model.py b/Server/bkr/server/model.py
index 68ef86a..5fd611f 100644
--- a/Server/bkr/server/model.py
+++ b/Server/bkr/server/model.py
@@ -1062,6 +1062,7 @@ class Permission(object):
"""
@classmethod
+ @cache
def by_name(cls, permission_name):
return cls.query.filter(cls.permission_name == permission_name).one()
@@ -1187,6 +1188,7 @@ class Group(object):
An ultra-simple group definition.
"""
@classmethod
+ @cache
def by_name(cls, name):
return cls.query.filter_by(group_name=name).one()
@@ -2370,6 +2372,7 @@ class SystemType(SystemObject):
return [type.type for type in all_types]
@classmethod
+ @cache
def by_name(cls, systemtype):
return cls.query.filter_by(type=systemtype).one()
@@ -2443,6 +2446,7 @@ class SystemStatus(SystemObject):
@classmethod
+ @cache
def by_name(cls, systemstatus):
return cls.query.filter_by(status=systemstatus).one()
@@ -3279,6 +3283,7 @@ class TaskStatus(object):
return cls.query().order_by(TaskStatus.severity.desc()).first()
@classmethod
+ @cache
def by_name(cls, status_name):
return cls.query().filter_by(status=status_name).one()
@@ -3307,6 +3312,7 @@ class TaskStatus(object):
class TaskResult(object):
@classmethod
+ @cache
def by_name(cls, result_name):
return cls.query().filter_by(result=result_name).one()
@@ -3777,6 +3783,7 @@ class Product(object):
return cls.query().filter(cls.id == id).one()
@classmethod
+ @cache
def by_name(cls, name):
return cls.query().filter(cls.name == name).one()
@@ -5460,6 +5467,7 @@ class Task(MappedObject):
"""
@classmethod
+ @cache
def by_name(cls, name):
return cls.query.filter_by(name=name).one()
@@ -5568,6 +5576,7 @@ class TaskType(MappedObject):
"""
@classmethod
+ @cache
def by_name(cls, type):
return cls.query.filter_by(type=type).one()
@@ -5578,6 +5587,7 @@ class TaskPackage(MappedObject):
"""
@classmethod
+ @cache
def by_name(cls, package):
return cls.query.filter_by(package=package).one()