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
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