From 39b772844dcad70ab45a12db042db4a5ee4208a6 Mon Sep 17 00:00:00 2001 From: Thomas Herve Date: Mon, 15 Feb 2016 05:53:17 +0100 Subject: [PATCH] Don't query stack tags twice Retrieving the field from the db object triggers the query to stack_tags, so we don't need to do it a second time to retrieve the list of tags. Instead, use the data directly. Change-Id: Ibe6ac45d54afca6588b1b71ffa7278977d2f4d8a --- heat/objects/stack.py | 7 ++----- heat/objects/stack_tag.py | 5 +++++ 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/heat/objects/stack.py b/heat/objects/stack.py index 8420bec00a..8e8f001ea3 100644 --- a/heat/objects/stack.py +++ b/heat/objects/stack.py @@ -71,11 +71,8 @@ class Stack( raw_template.RawTemplate.get_by_id( context, db_stack['raw_template_id'])) elif field == 'tags': - if db_stack.get(field) is not None: - stack['tags'] = stack_tag.StackTagList.get( - context, db_stack['id']) - else: - stack['tags'] = None + stack['tags'] = stack_tag.StackTagList.from_db_object( + context, db_stack.get(field)) else: stack[field] = db_stack.__dict__.get(field) stack._context = context diff --git a/heat/objects/stack_tag.py b/heat/objects/stack_tag.py index 7a5bb312a3..50d86deda7 100644 --- a/heat/objects/stack_tag.py +++ b/heat/objects/stack_tag.py @@ -80,3 +80,8 @@ class StackTagList( @classmethod def delete(cls, context, stack_id): db_api.stack_tags_delete(context, stack_id) + + @classmethod + def from_db_object(cls, context, db_tags): + if db_tags is not None: + return base.obj_make_list(context, cls(), StackTag, db_tags)