mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-05-05 08:31:00 -04:00
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:
@@ -3,6 +3,7 @@ import uuid
|
||||
from app.models.service import Service
|
||||
from app.models.user import User
|
||||
from tests import organisation_json
|
||||
from tests.conftest import ORGANISATION_ID
|
||||
|
||||
INV_PARENT_FOLDER_ID = '7e979e79-d970-43a5-ac69-b625a8d147b0'
|
||||
INV_CHILD_1_FOLDER_ID = '92ee1ee0-e4ee-4dcc-b1a7-a5da9ebcfa2b'
|
||||
@@ -176,18 +177,21 @@ def test_get_template_folders_shows_all_folders_when_user_id_not_passed_in(
|
||||
]
|
||||
|
||||
|
||||
def test_organisation_type_when_services_organisation_has_no_org_type(mocker, service_one, organisation_one):
|
||||
def test_organisation_type_when_services_organisation_has_no_org_type(mocker, service_one):
|
||||
service = Service(service_one)
|
||||
mocker.patch('app.organisations_client.get_service_organisation', return_value=organisation_one)
|
||||
service._dict['organisation_id'] = ORGANISATION_ID
|
||||
org = organisation_json(organisation_type=None)
|
||||
mocker.patch('app.organisations_client.get_organisation', return_value=org)
|
||||
|
||||
assert not organisation_one['organisation_type']
|
||||
assert not org['organisation_type']
|
||||
assert service.organisation_type == 'central'
|
||||
|
||||
|
||||
def test_organisation_type_when_service_and_its_org_both_have_an_org_type(mocker, service_one):
|
||||
# service_one has an organisation_type of 'central'
|
||||
service = Service(service_one)
|
||||
service._dict['organisation'] = ORGANISATION_ID
|
||||
org = organisation_json(organisation_type='local')
|
||||
mocker.patch('app.organisations_client.get_service_organisation', return_value=org)
|
||||
mocker.patch('app.organisations_client.get_organisation', return_value=org)
|
||||
|
||||
assert service.organisation_type == 'local'
|
||||
|
||||
Reference in New Issue
Block a user