From 4c148c7c2324519b6bd363bdc062287f1fdd62ac Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Mon, 3 Dec 2018 13:19:28 +0000 Subject: [PATCH] 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. --- app/main/views/templates.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/main/views/templates.py b/app/main/views/templates.py index ad81a475e..5e4617ba9 100644 --- a/app/main/views/templates.py +++ b/app/main/views/templates.py @@ -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') )