Cache organisations, not just domains in Redis

This should make the ‘All organisations’ page load a lil’ bit quicker.
Still worth caching the domains separately so the response is smaller
when we only care about domains. This is because the code that uses the
domains is part of the sign up flow, so it’s really important that it’s
snappy.
This commit is contained in:
Chris Hill-Scott
2019-06-14 11:10:57 +01:00
parent c7325576d6
commit 8f9ade7a8b
4 changed files with 87 additions and 15 deletions

View File

@@ -900,24 +900,42 @@ def test_clear_cache_shows_form(client_request, platform_admin_user, mocker):
assert page.select('input[type=radio]')[0]['value'] == 'user'
assert page.select('input[type=radio]')[1]['value'] == 'service'
assert page.select('input[type=radio]')[2]['value'] == 'template'
assert page.select('input[type=radio]')[3]['value'] == 'email_branding'
assert page.select('input[type=radio]')[4]['value'] == 'letter_branding'
assert page.select('input[type=radio]')[5]['value'] == 'organisation'
assert not redis.delete_cache_keys_by_pattern.called
def test_clear_cache_submits_and_tells_you_how_many_things_were_deleted(client_request, platform_admin_user, mocker):
@pytest.mark.parametrize('model_type, expected_calls, expected_confirmation', (
('template', [
call('service-????????-????-????-????-????????????-templates'),
call('template-????????-????-????-????-????????????-version-*'),
call('template-????????-????-????-????-????????????-versions'),
], 'Removed 3 template objects from redis'),
('organisation', [
call('organisations'),
call('domains'),
call('live-service-and-organisation-counts'),
], 'Removed 3 organisation objects from redis'),
))
def test_clear_cache_submits_and_tells_you_how_many_things_were_deleted(
client_request,
platform_admin_user,
mocker,
model_type,
expected_calls,
expected_confirmation,
):
redis = mocker.patch('app.main.views.platform_admin.redis_client')
redis.delete_cache_keys_by_pattern.side_effect = [0, 3, 1]
client_request.login(platform_admin_user)
page = client_request.post('main.clear_cache', _data={'model_type': 'template'}, _expected_status=200)
page = client_request.post('main.clear_cache', _data={'model_type': model_type}, _expected_status=200)
assert redis.delete_cache_keys_by_pattern.call_args_list == [
call('service-????????-????-????-????-????????????-templates'),
call('template-????????-????-????-????-????????????-version-*'),
call('template-????????-????-????-????-????????????-versions'),
]
assert redis.delete_cache_keys_by_pattern.call_args_list == expected_calls
flash_banner = page.find('div', class_='banner-default')
assert flash_banner.text.strip() == 'Removed 3 template objects from redis'
assert flash_banner.text.strip() == expected_confirmation
def test_clear_cache_requires_option(client_request, platform_admin_user, mocker):