Use the cached template object.

By adding SerialisedTemplate we can avoid a database call for the template. This is useful when sending many many emails/sms for the same template/version.
This commit is contained in:
Rebecca Law
2021-02-11 16:08:46 +00:00
parent 2270832873
commit 200f8aad81
2 changed files with 59 additions and 3 deletions

View File

@@ -28,6 +28,7 @@ from app.models import (
NOTIFICATION_SENDING,
NOTIFICATION_STATUS_TYPES_COMPLETED
)
from app.serialised_models import SerialisedTemplate
def send_sms_to_provider(notification):
@@ -40,10 +41,12 @@ def send_sms_to_provider(notification):
if notification.status == 'created':
provider = provider_to_use(SMS_TYPE, notification.international)
template_model = dao_get_template_by_id(notification.template_id, notification.template_version)
template_dict = SerialisedTemplate.get_dict(template_id=notification.template_id,
service_id=service_id,
version=notification.template_version)['data']
template = SMSMessageTemplate(
template_model.__dict__,
template_dict,
values=notification.personalisation,
prefix=service.name,
show_prefix=service.prefix_sms,
@@ -92,7 +95,9 @@ def send_email_to_provider(notification):
if notification.status == 'created':
provider = provider_to_use(EMAIL_TYPE)
template_dict = dao_get_template_by_id(notification.template_id, notification.template_version).__dict__
template_dict = SerialisedTemplate.get_dict(template_id=notification.template_id,
service_id=service_id,
version=notification.template_version)['data']
html_email = HTMLEmailTemplate(
template_dict,