Cache organisation name in Redis

A lot of pages in the admin app are now generated entirely from Redis,
without touching the API.

The one remaining API call that a lot of pages make, when the user is
platform admin or a member of an organisation, is to get the name of
the current service’s organisation.

This commit adds some code to start caching that as well, which should
speed up page load times for when we’re clicking around the admin app
(it’s typically 100ms just to get the organisation, and more than that
when the API is under load).

This means changing the service model to get the organisation from the
API by ID, not by service ID. Otherwise it would be very hard to clear
the cache if the name of the organisation ever changed.

We can’t cache the whole organisation because it has a
`count_of_live_services` field which can change at any time, without an
update being made.
This commit is contained in:
Chris Hill-Scott
2020-03-20 08:42:33 +00:00
parent c448eb8995
commit cc5701e870
19 changed files with 264 additions and 131 deletions

View File

@@ -1,4 +1,4 @@
from unittest.mock import ANY, Mock
from unittest.mock import ANY, Mock, PropertyMock
import pytest
from bs4 import BeautifulSoup
@@ -200,7 +200,12 @@ def test_gps_can_create_own_organisations(
organisation,
expected_status,
):
mocker.patch('app.organisations_client.get_service_organisation', return_value=organisation)
mocker.patch(
'app.models.service.Service.organisation_id',
new_callable=PropertyMock,
return_value=ORGANISATION_ID,
)
mocker.patch('app.organisations_client.get_organisation', return_value=organisation)
service_one['organisation_type'] = organisation_type
page = client_request.get(
@@ -234,7 +239,12 @@ def test_nhs_local_can_create_own_organisations(
organisation,
expected_status,
):
mocker.patch('app.organisations_client.get_service_organisation', return_value=organisation)
mocker.patch(
'app.models.service.Service.organisation_id',
new_callable=PropertyMock,
return_value=ORGANISATION_ID,
)
mocker.patch('app.organisations_client.get_organisation', return_value=organisation)
mocker.patch(
'app.models.organisation.Organisations.client_method',
return_value=[
@@ -300,7 +310,6 @@ def test_gps_can_name_their_organisation(
data,
expected_service_name,
):
mocker.patch('app.organisations_client.get_service_organisation', return_value=None)
service_one['organisation_type'] = 'nhs_gp'
mock_create_organisation = mocker.patch(
'app.organisations_client.create_organisation',
@@ -350,7 +359,6 @@ def test_validation_of_gps_creating_organisations(
data,
expected_error,
):
mocker.patch('app.organisations_client.get_service_organisation', return_value=None)
service_one['organisation_type'] = 'nhs_gp'
page = client_request.post(
'.add_organisation_from_gp_service',
@@ -368,7 +376,6 @@ def test_nhs_local_assigns_to_selected_organisation(
mock_get_organisation,
mock_update_service_organisation,
):
mocker.patch('app.organisations_client.get_service_organisation', return_value=None)
mocker.patch(
'app.models.organisation.Organisations.client_method',
return_value=[
@@ -652,8 +659,8 @@ def test_organisation_settings_for_platform_admin(
):
expected_rows = [
'Label Value Action',
'Name Org 1 Change',
'Sector Not set Change',
'Name Test organisation Change',
'Sector Central government Change',
'Crown organisation Yes Change',
'Data sharing and financial agreement Not signed Change',
'Request to go live notes None Change',
@@ -686,7 +693,7 @@ def test_organisation_settings_for_platform_admin(
('school_or_college', 'School or college'),
('other', 'Other'),
),
None,
'central',
),
(
'.edit_organisation_crown_status',

View File

@@ -118,7 +118,7 @@ def test_cancelled_invite_opened_by_user(
) == 'Test User decided to cancel this invitation.'
assert normalize_spaces(
page.select('main p')[1].text
) == 'If you need access to Org 1, youll have to ask them to invite you again.'
) == 'If you need access to Test organisation, youll have to ask them to invite you again.'
mock_get_user.assert_called_once_with(fake_uuid)
mock_get_organisation.assert_called_once_with(ORGANISATION_ID)