Look at other services only if no templates

This saves one call to the API or Redis in the common case where the
current service does have templates.

This is because `any()` evaluates all expressions before running,
whereas `or` will only evaluate the second expression if the first
returns `False`-y.
This commit is contained in:
Chris Hill-Scott
2018-12-03 13:19:28 +00:00
parent 8d0b3f47fd
commit 4c148c7c23

View File

@@ -258,10 +258,10 @@ def add_template_by_type(service_id, template_folder_id=None):
form = ChooseTemplateType(
include_letters=current_service.has_permission('letter'),
include_copy=any((
len(current_service.all_templates) > 0,
len(user_api_client.get_service_ids_for_user(current_user)) > 1,
)),
include_copy=(
current_service.all_templates or
len(user_api_client.get_service_ids_for_user(current_user)) > 1
),
include_folder=current_service.has_permission('edit_folders')
)