From 20cc1e230fbbd95afa687185735d3ac818f1abe1 Mon Sep 17 00:00:00 2001 From: David McDonald Date: Wed, 24 Nov 2021 18:10:30 +0000 Subject: [PATCH] Reduce TTL to 1 hour for get_count_of_live_services_and_organisations This stat is shown on a few of our pages, such as our homepage, the performance page and also a platform admin page and is currently catched for the default TTL of 1 week. I think there is no reason we can't make this only cache once an hour and give slightly more up to date stats which will update more regularly. This mimics the approach and also the TTL choice of 1 hour that has been added for the performance page (although there is no particular bug here to fix, it is just nice to have slightly more up up to date data). Note, the API call only takes about 0.3 seconds at the moment so it is not particularly intensive on the DB to run this more regularly. --- app/notify_client/status_api_client.py | 2 +- tests/app/notify_client/test_status_api_client.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/notify_client/status_api_client.py b/app/notify_client/status_api_client.py index 7228621c6..f3224b41d 100644 --- a/app/notify_client/status_api_client.py +++ b/app/notify_client/status_api_client.py @@ -6,7 +6,7 @@ class StatusApiClient(NotifyAdminAPIClient): def get_status(self, *params): return self.get(url='/_status', *params) - @cache.set('live-service-and-organisation-counts') + @cache.set('live-service-and-organisation-counts', ttl_in_seconds=3600) def get_count_of_live_services_and_organisations(self): return self.get(url='/_status/live-service-and-organisation-counts') diff --git a/tests/app/notify_client/test_status_api_client.py b/tests/app/notify_client/test_status_api_client.py index f836056bb..e434bc9d1 100644 --- a/tests/app/notify_client/test_status_api_client.py +++ b/tests/app/notify_client/test_status_api_client.py @@ -33,7 +33,7 @@ def test_sets_value_in_cache(mocker): mock_redis_set.assert_called_once_with( 'live-service-and-organisation-counts', '{"data_from": "api"}', - ex=604800 + ex=3600 )