summaryrefslogtreecommitdiff
path: root/heat/objects
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2016-08-24 17:12:01 +0000
committerGerrit Code Review <review@openstack.org>2016-08-24 17:12:01 +0000
commitd86ea51bbddddd7ea5f0c2313a4fe42fe36bc336 (patch)
treec15b8cb7f1dd0a2948e5aee4615fcf3c308b471f /heat/objects
parent90dcdbaefe97318cb7cf3912baf5fcbf51a62fa9 (diff)
parentbc3b84fb609985511510aff2aee62dbf05268b81 (diff)
downloadheat-d86ea51bbddddd7ea5f0c2313a4fe42fe36bc336.tar.gz
Merge "A context cache for Resource objects"
Diffstat (limited to 'heat/objects')
-rw-r--r--heat/objects/resource.py26
1 files changed, 24 insertions, 2 deletions
diff --git a/heat/objects/resource.py b/heat/objects/resource.py
index 968781224..69cfd5177 100644
--- a/heat/objects/resource.py
+++ b/heat/objects/resource.py
@@ -15,6 +15,8 @@
"""Resource object."""
+import collections
+
from oslo_config import cfg
from oslo_serialization import jsonutils
from oslo_versionedobjects import base
@@ -42,6 +44,19 @@ def retry_on_conflict(func):
return wrapper(func)
+class ResourceCache(object):
+
+ def __init__(self):
+ self.delete_all()
+
+ def delete_all(self):
+ self.by_stack_id_name = collections.defaultdict(dict)
+
+ def set_by_stack_id(self, resources):
+ for res in six.itervalues(resources):
+ self.by_stack_id_name[res.stack_id][res.name] = res
+
+
class Resource(
heat_base.HeatObject,
base.VersionedObjectDictCompat,
@@ -136,6 +151,10 @@ class Resource(
@classmethod
def get_all_by_stack(cls, context, stack_id, filters=None):
+ cache = context.cache(ResourceCache)
+ resources = cache.by_stack_id_name.get(stack_id)
+ if resources:
+ return dict(resources)
resources_db = db_api.resource_get_all_by_stack(context, stack_id,
filters)
return cls._resources_to_dict(context, resources_db)
@@ -165,12 +184,15 @@ class Resource(
return dict(resources)
@classmethod
- def get_all_by_root_stack(cls, context, stack_id, filters):
+ def get_all_by_root_stack(cls, context, stack_id, filters, cache=False):
resources_db = db_api.resource_get_all_by_root_stack(
context,
stack_id,
filters)
- return cls._resources_to_dict(context, resources_db)
+ all = cls._resources_to_dict(context, resources_db)
+ if cache:
+ context.cache(ResourceCache).set_by_stack_id(all)
+ return all
@classmethod
def purge_deleted(cls, context, stack_id):