Files
notifications-admin/app/notify_client/broadcast_message_api_client.py
Chris Hill-Scott 058553b6ee Cache broadcast messages in Redis
This should make the pages slightly quicker to load, because Redis will
return the JSON string faster than the API.

The only change that can happen to a broadcast which doesn’t go through
the admin app is a broadcast ending at its scheduled time. So this could
result in a cached broadcast having a status of `broadcasting` when it
had in fact finished. We already account for this here though:
b2b58ec044/app/models/broadcast_message.py (L89-L94)
2020-08-03 11:38:10 +01:00

53 lines
1.6 KiB
Python

from app.notify_client import NotifyAdminAPIClient, _attach_current_user, cache
class BroadcastMessageAPIClient(NotifyAdminAPIClient):
def create_broadcast_message(
self,
*,
service_id,
template_id,
):
data = {
"service_id": service_id,
"template_id": template_id,
"personalisation": {},
}
data = _attach_current_user(data)
broadcast_message = self.post(
f'/service/{service_id}/broadcast-message',
data=data,
)
return broadcast_message
def get_broadcast_messages(self, service_id):
return self.get(f'/service/{service_id}/broadcast-message')['broadcast_messages']
@cache.set('broadcast-message-{broadcast_message_id}')
def get_broadcast_message(self, *, service_id, broadcast_message_id):
return self.get(f'/service/{service_id}/broadcast-message/{broadcast_message_id}')
@cache.delete('broadcast-message-{broadcast_message_id}')
def update_broadcast_message(self, *, service_id, broadcast_message_id, data):
self.post(
f'/service/{service_id}/broadcast-message/{broadcast_message_id}',
data=data,
)
@cache.delete('broadcast-message-{broadcast_message_id}')
def update_broadcast_message_status(self, status, *, service_id, broadcast_message_id):
data = _attach_current_user({
'status': status,
})
self.post(
f'/service/{service_id}/broadcast-message/{broadcast_message_id}/status',
data=data,
)
broadcast_message_api_client = BroadcastMessageAPIClient()