From f1da4547beff30c922bdf8dca7e074f64bd6ae88 Mon Sep 17 00:00:00 2001 From: Zane Bitter Date: Mon, 2 Sep 2013 16:00:36 +0200 Subject: [PATCH] Don't use a query for stack_get() When getting a database record by ID, it is much more efficient to get() it directly than to perform a query or the database to obtain the ID (again) and then get it. Since stack_get() returns only a single record that can be trivially checked for deletion in code, do this rather than performing a query with a filter. Change-Id: I4bb3ea1a9c4ae928fe0f5bce5c02b842a3f1ab4f --- heat/db/sqlalchemy/api.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/heat/db/sqlalchemy/api.py b/heat/db/sqlalchemy/api.py index 58b19995..dd1716f2 100644 --- a/heat/db/sqlalchemy/api.py +++ b/heat/db/sqlalchemy/api.py @@ -190,10 +190,10 @@ def stack_get_by_name(context, stack_name, owner_id=None): def stack_get(context, stack_id, admin=False, show_deleted=False): - result = soft_delete_aware_query(context, - models.Stack, - show_deleted=show_deleted).\ - filter_by(id=stack_id).first() + result = model_query(context, models.Stack).get(stack_id) + + if result is None or result.deleted_at is not None and not show_deleted: + return None # If the admin flag is True, we allow retrieval of a specific # stack without the tenant scoping -- 2.45.2