Always eager load the raw_template for a stack
The vast majority of stack fetches are immediately followed by a raw_template fetch, so this change always eagerly fetches the raw_template for every stack fetch. During stack versioned object creation the stack's raw_template object is used to construct the versioned raw template object. Change-Id: I1a6fb8fb7d069b50dd5d623c989acd5582818ae1 Related-Bug: #1479723 Related-Bug: #1523748
This commit is contained in:
parent
d072f6e7f1
commit
3ab0ede98c
|
@ -156,11 +156,9 @@ def resource_get_by_physical_resource_id(context, physical_resource_id):
|
||||||
physical_resource_id)
|
physical_resource_id)
|
||||||
|
|
||||||
|
|
||||||
def stack_get(context, stack_id, show_deleted=False, tenant_safe=True,
|
def stack_get(context, stack_id, show_deleted=False, tenant_safe=True):
|
||||||
eager_load=False):
|
|
||||||
return IMPL.stack_get(context, stack_id, show_deleted=show_deleted,
|
return IMPL.stack_get(context, stack_id, show_deleted=show_deleted,
|
||||||
tenant_safe=tenant_safe,
|
tenant_safe=tenant_safe)
|
||||||
eager_load=eager_load)
|
|
||||||
|
|
||||||
|
|
||||||
def stack_get_status(context, stack_id):
|
def stack_get_status(context, stack_id):
|
||||||
|
|
|
@ -415,28 +415,26 @@ def resource_get_all_by_root_stack(context, stack_id, filters=None):
|
||||||
def stack_get_by_name_and_owner_id(context, stack_name, owner_id):
|
def stack_get_by_name_and_owner_id(context, stack_name, owner_id):
|
||||||
query = soft_delete_aware_query(
|
query = soft_delete_aware_query(
|
||||||
context, models.Stack
|
context, models.Stack
|
||||||
).filter(sqlalchemy.or_(
|
).options(orm.joinedload("raw_template")).filter(sqlalchemy.or_(
|
||||||
models.Stack.tenant == context.tenant_id,
|
models.Stack.tenant == context.tenant_id,
|
||||||
models.Stack.stack_user_project_id == context.tenant_id)
|
models.Stack.stack_user_project_id == context.tenant_id)
|
||||||
).filter_by(name=stack_name).filter_by(owner_id=owner_id)
|
).filter_by(name=stack_name).filter_by(owner_id=owner_id)
|
||||||
return query.first()
|
return query.first()
|
||||||
|
|
||||||
|
|
||||||
def stack_get_by_name(context, stack_name):
|
def stack_get_by_name(context, stack_name):
|
||||||
query = soft_delete_aware_query(
|
query = soft_delete_aware_query(
|
||||||
context, models.Stack
|
context, models.Stack
|
||||||
).filter(sqlalchemy.or_(
|
).options(orm.joinedload("raw_template")).filter(sqlalchemy.or_(
|
||||||
models.Stack.tenant == context.tenant_id,
|
models.Stack.tenant == context.tenant_id,
|
||||||
models.Stack.stack_user_project_id == context.tenant_id)
|
models.Stack.stack_user_project_id == context.tenant_id)
|
||||||
).filter_by(name=stack_name)
|
).filter_by(name=stack_name)
|
||||||
return query.first()
|
return query.first()
|
||||||
|
|
||||||
|
|
||||||
def stack_get(context, stack_id, show_deleted=False, tenant_safe=True,
|
def stack_get(context, stack_id, show_deleted=False, tenant_safe=True):
|
||||||
eager_load=False):
|
query = context.session.query(models.Stack).options(
|
||||||
query = context.session.query(models.Stack)
|
orm.joinedload("raw_template"))
|
||||||
if eager_load:
|
|
||||||
query = query.options(orm.joinedload("raw_template"))
|
|
||||||
result = query.get(stack_id)
|
result = query.get(stack_id)
|
||||||
|
|
||||||
deleted_ok = show_deleted or context.show_deleted
|
deleted_ok = show_deleted or context.show_deleted
|
||||||
|
@ -569,6 +567,7 @@ def stack_get_all(context, limit=None, sort_keys=None, marker=None,
|
||||||
show_hidden=show_hidden, tags=tags,
|
show_hidden=show_hidden, tags=tags,
|
||||||
tags_any=tags_any, not_tags=not_tags,
|
tags_any=tags_any, not_tags=not_tags,
|
||||||
not_tags_any=not_tags_any)
|
not_tags_any=not_tags_any)
|
||||||
|
query = query.options(orm.joinedload("raw_template"))
|
||||||
return _filter_and_page_query(context, query, limit, sort_keys,
|
return _filter_and_page_query(context, query, limit, sort_keys,
|
||||||
marker, sort_dir, filters).all()
|
marker, sort_dir, filters).all()
|
||||||
|
|
||||||
|
|
|
@ -481,8 +481,7 @@ class EngineService(service.Service):
|
||||||
s = stack_object.Stack.get_by_id(
|
s = stack_object.Stack.get_by_id(
|
||||||
cnxt,
|
cnxt,
|
||||||
identity.stack_id,
|
identity.stack_id,
|
||||||
show_deleted=show_deleted,
|
show_deleted=show_deleted)
|
||||||
eager_load=True)
|
|
||||||
|
|
||||||
if s is None:
|
if s is None:
|
||||||
raise exception.EntityNotFound(entity='Stack',
|
raise exception.EntityNotFound(entity='Stack',
|
||||||
|
@ -2292,8 +2291,7 @@ class EngineService(service.Service):
|
||||||
s = stack_object.Stack.get_by_id(
|
s = stack_object.Stack.get_by_id(
|
||||||
cnxt,
|
cnxt,
|
||||||
stack_id,
|
stack_id,
|
||||||
tenant_safe=False,
|
tenant_safe=False)
|
||||||
eager_load=True)
|
|
||||||
if s.status != parser.Stack.IN_PROGRESS:
|
if s.status != parser.Stack.IN_PROGRESS:
|
||||||
lock.release()
|
lock.release()
|
||||||
continue
|
continue
|
||||||
|
|
|
@ -69,8 +69,7 @@ class StackWatch(object):
|
||||||
admin_context = context.get_admin_context()
|
admin_context = context.get_admin_context()
|
||||||
db_stack = stack_object.Stack.get_by_id(admin_context,
|
db_stack = stack_object.Stack.get_by_id(admin_context,
|
||||||
sid,
|
sid,
|
||||||
tenant_safe=False,
|
tenant_safe=False)
|
||||||
eager_load=True)
|
|
||||||
if not db_stack:
|
if not db_stack:
|
||||||
LOG.error(_LE("Unable to retrieve stack %s for periodic task"),
|
LOG.error(_LE("Unable to retrieve stack %s for periodic task"),
|
||||||
sid)
|
sid)
|
||||||
|
|
|
@ -487,8 +487,7 @@ class Stack(collections.Mapping):
|
||||||
stack = stack_object.Stack.get_by_id(
|
stack = stack_object.Stack.get_by_id(
|
||||||
context,
|
context,
|
||||||
stack_id,
|
stack_id,
|
||||||
show_deleted=show_deleted,
|
show_deleted=show_deleted)
|
||||||
eager_load=True)
|
|
||||||
if stack is None:
|
if stack is None:
|
||||||
message = _('No stack exists with id "%s"') % str(stack_id)
|
message = _('No stack exists with id "%s"') % str(stack_id)
|
||||||
raise exception.NotFound(message)
|
raise exception.NotFound(message)
|
||||||
|
|
|
@ -265,8 +265,7 @@ class WatchRule(object):
|
||||||
else:
|
else:
|
||||||
s = stack_object.Stack.get_by_id(
|
s = stack_object.Stack.get_by_id(
|
||||||
self.context,
|
self.context,
|
||||||
self.stack_id,
|
self.stack_id)
|
||||||
eager_load=True)
|
|
||||||
stk = stack.Stack.load(self.context, stack=s)
|
stk = stack.Stack.load(self.context, stack=s)
|
||||||
if (stk.action != stk.DELETE
|
if (stk.action != stk.DELETE
|
||||||
and stk.status == stk.COMPLETE):
|
and stk.status == stk.COMPLETE):
|
||||||
|
|
|
@ -52,7 +52,7 @@ class RawTemplate(
|
||||||
}
|
}
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _from_db_object(context, tpl, db_tpl):
|
def from_db_object(context, tpl, db_tpl):
|
||||||
for field in tpl.fields:
|
for field in tpl.fields:
|
||||||
tpl[field] = db_tpl[field]
|
tpl[field] = db_tpl[field]
|
||||||
|
|
||||||
|
@ -85,7 +85,7 @@ class RawTemplate(
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_by_id(cls, context, template_id):
|
def get_by_id(cls, context, template_id):
|
||||||
raw_template_db = db_api.raw_template_get(context, template_id)
|
raw_template_db = db_api.raw_template_get(context, template_id)
|
||||||
return cls._from_db_object(context, cls(), raw_template_db)
|
return cls.from_db_object(context, cls(), raw_template_db)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def encrypt_hidden_parameters(cls, tmpl):
|
def encrypt_hidden_parameters(cls, tmpl):
|
||||||
|
@ -100,8 +100,8 @@ class RawTemplate(
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def create(cls, context, values):
|
def create(cls, context, values):
|
||||||
return cls._from_db_object(context, cls(),
|
return cls.from_db_object(context, cls(),
|
||||||
db_api.raw_template_create(context, values))
|
db_api.raw_template_create(context, values))
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def update_by_id(cls, context, template_id, values):
|
def update_by_id(cls, context, template_id, values):
|
||||||
|
@ -109,7 +109,7 @@ class RawTemplate(
|
||||||
# table, not in the old location of raw_template.files
|
# table, not in the old location of raw_template.files
|
||||||
if 'files_id' in values and values['files_id']:
|
if 'files_id' in values and values['files_id']:
|
||||||
values['files'] = None
|
values['files'] = None
|
||||||
return cls._from_db_object(
|
return cls.from_db_object(
|
||||||
context, cls(),
|
context, cls(),
|
||||||
db_api.raw_template_update(context, template_id, values))
|
db_api.raw_template_update(context, template_id, values))
|
||||||
|
|
||||||
|
|
|
@ -68,8 +68,10 @@ class Stack(
|
||||||
for field in stack.fields:
|
for field in stack.fields:
|
||||||
if field == 'raw_template':
|
if field == 'raw_template':
|
||||||
stack['raw_template'] = (
|
stack['raw_template'] = (
|
||||||
raw_template.RawTemplate.get_by_id(
|
raw_template.RawTemplate.from_db_object(
|
||||||
context, db_stack['raw_template_id']))
|
context,
|
||||||
|
raw_template.RawTemplate(),
|
||||||
|
db_stack['raw_template']))
|
||||||
else:
|
else:
|
||||||
stack[field] = db_stack.__dict__.get(field)
|
stack[field] = db_stack.__dict__.get(field)
|
||||||
stack._context = context
|
stack._context = context
|
||||||
|
|
|
@ -1385,8 +1385,8 @@ class StackServiceTest(common.HeatTestCase):
|
||||||
tenant_safe=False,
|
tenant_safe=False,
|
||||||
show_nested=True)
|
show_nested=True)
|
||||||
mock_get_by_id.assert_has_calls([
|
mock_get_by_id.assert_has_calls([
|
||||||
mock.call(self.ctx, 'foo', tenant_safe=False, eager_load=True),
|
mock.call(self.ctx, 'foo', tenant_safe=False),
|
||||||
mock.call(self.ctx, 'bar', tenant_safe=False, eager_load=True),
|
mock.call(self.ctx, 'bar', tenant_safe=False),
|
||||||
])
|
])
|
||||||
mock_stack_load.assert_called_once_with(self.ctx,
|
mock_stack_load.assert_called_once_with(self.ctx,
|
||||||
stack=db_stack,
|
stack=db_stack,
|
||||||
|
|
Loading…
Reference in New Issue