Do a single query to fetch all event_list stacks

In preperation for supporting event list --nested-depth, do a single
query to fetch the stacks that correspond to the event list.

Related-Bug: #1588561

Change-Id: I106c21bbb87b9a591f3aba7de03eb130e7fd7b19
This commit is contained in:
Steve Baker 2016-06-03 15:10:05 +12:00
parent 7bfbace79f
commit 2a04ea4bb5

View File

@ -1591,39 +1591,34 @@ class EngineService(service.Service):
:param sort_dir: the direction of the sort ('asc' or 'desc'). :param sort_dir: the direction of the sort ('asc' or 'desc').
""" """
stacks = {} stack_identifiers = None
if stack_identity is not None: if stack_identity is not None:
st = self._get_stack(cnxt, stack_identity, show_deleted=True) st = self._get_stack(cnxt, stack_identity, show_deleted=True)
stacks[st.id] = st
events = event_object.Event.get_all_by_stack( events = list(event_object.Event.get_all_by_stack(
cnxt, cnxt,
st.id, st.id,
limit=limit, limit=limit,
marker=marker, marker=marker,
sort_keys=sort_keys, sort_keys=sort_keys,
sort_dir=sort_dir, sort_dir=sort_dir,
filters=filters) filters=filters))
stack_identifiers = {st.id: st.identifier()}
else: else:
events = event_object.Event.get_all_by_tenant( events = list(event_object.Event.get_all_by_tenant(
cnxt, limit=limit, cnxt, limit=limit,
marker=marker, marker=marker,
sort_keys=sort_keys, sort_keys=sort_keys,
sort_dir=sort_dir, sort_dir=sort_dir,
filters=filters) filters=filters))
def get_stack_identifier(stack_id): stack_ids = {e.stack_id for e in events}
if stack_id not in stacks: stacks = stack_object.Stack.get_all(cnxt,
s = stack_object.Stack.get_by_id( filters={'id': stack_ids},
cnxt, show_nested=True)
stack_id, stack_identifiers = {s.id: s.identifier() for s in stacks}
show_deleted=True)
if not s:
return
stacks[stack_id] = s
return stacks[stack_id].identifier()
return [api.format_event(e, get_stack_identifier(e.stack_id)) return [api.format_event(e, stack_identifiers.get(e.stack_id))
for e in events] for e in events]
def _authorize_stack_user(self, cnxt, stack, resource_name): def _authorize_stack_user(self, cnxt, stack, resource_name):