Remove content and subject from get all templates

Content and subject are user-submitted so are effectively unbounded in
size. And we’re serialising them for every template when sending the
list of templates to the admin app.

For the service with the most templates this results in a 1.3Mb blob of
JSON going over the wire, and being cached in Redis.

And then the admin app completely ignores these fields, because it does
show template content until you’ve clicked into a single template.

This commit adds a new query parameter, `detailed`, that the admin app
can set to `False`. When it does only the fields needed to render the
`/templates` page are returned.

This is done with a new parameter so as not to break the V1 API.
Although I looked in Kibana and it doesn’t seem like anyone external is
using this endpoint we’ve come this far without breaking the API so…
This commit is contained in:
Chris Hill-Scott
2020-06-16 17:10:25 +01:00
parent dcc407efea
commit 718f8ccad0
3 changed files with 89 additions and 2 deletions

View File

@@ -499,6 +499,67 @@ def test_should_get_only_templates_for_that_service(admin_request, notify_db_ses
assert {template['id'] for template in json_resp_2['data']} == {str(id_3)}
@pytest.mark.parametrize('extra_args', (
{},
{'detailed': True},
{'detailed': 'True'},
))
def test_should_get_return_all_fields_by_default(
admin_request,
sample_email_template,
extra_args,
):
json_response = admin_request.get(
'template.get_all_templates_for_service',
service_id=sample_email_template.service.id,
**extra_args
)
assert json_response['data'][0].keys() == {
'archived',
'content',
'created_at',
'created_by',
'folder',
'hidden',
'id',
'name',
'postage',
'process_type',
'redact_personalisation',
'reply_to',
'reply_to_text',
'service',
'service_letter_contact',
'subject',
'template_redacted',
'template_type',
'updated_at',
'version',
}
@pytest.mark.parametrize('extra_args', (
{'detailed': False},
{'detailed': 'False'},
))
def test_should_not_return_content_and_subject_if_requested(
admin_request,
sample_email_template,
extra_args,
):
json_response = admin_request.get(
'template.get_all_templates_for_service',
service_id=sample_email_template.service.id,
**extra_args
)
assert json_response['data'][0].keys() == {
'folder',
'id',
'name',
'template_type',
}
@pytest.mark.parametrize(
"subject, content, template_type", [
(