]> review.fuel-infra Code Review - openstack-build/heat-build.git/commitdiff
Don't use a query for stack_get()
authorZane Bitter <zbitter@redhat.com>
Mon, 2 Sep 2013 14:00:36 +0000 (16:00 +0200)
committerZane Bitter <zbitter@redhat.com>
Mon, 2 Sep 2013 14:00:36 +0000 (16:00 +0200)
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

index 58b1999534694e02623c46cce8a4b7ccbba806b9..dd1716f27ae6501f30724df5eab66477210f0474 100644 (file)
@@ -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