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

@@ -7,6 +7,7 @@ from app import organisations_client
@pytest.mark.parametrize(
(
'client_method,'
'expected_cache_get_calls,'
'cache_value,'
'expected_api_calls,'
@@ -15,13 +16,14 @@ from app import organisations_client
),
[
(
'get_domains',
[
call('domains')
call('domains'),
],
b"""
[
{"domains": ["a", "b", "c"]},
{"domains": ["c", "d", "e"]}
{"name": "org 1", "domains": ["a", "b", "c"]},
{"name": "org 2", "domains": ["c", "d", "e"]}
]
""",
[],
@@ -29,19 +31,62 @@ from app import organisations_client
['a', 'b', 'c', 'd', 'e'],
),
(
'get_domains',
[
call('domains')
call('domains'),
call('organisations'),
],
None,
[
call(url='/organisations')
],
[
call(
'organisations',
'[{"domains": ["x", "y", "z"]}]',
ex=604800,
),
call(
'domains',
'["x", "y", "z"]',
ex=604800
)
),
],
'from api',
),
(
'get_organisations',
[
call('organisations'),
],
b"""
[
{"name": "org 1", "domains": ["a", "b", "c"]},
{"name": "org 2", "domains": ["c", "d", "e"]}
]
""",
[],
[],
[
{"name": "org 1", "domains": ["a", "b", "c"]},
{"name": "org 2", "domains": ["c", "d", "e"]}
],
),
(
'get_organisations',
[
call('organisations'),
],
None,
[
call(url='/organisations')
],
[
call(
'organisations',
'[{"domains": ["x", "y", "z"]}]',
ex=604800,
),
],
'from api',
),
@@ -50,6 +95,7 @@ from app import organisations_client
def test_returns_value_from_cache(
app_,
mocker,
client_method,
expected_cache_get_calls,
cache_value,
expected_return_value,
@@ -71,7 +117,7 @@ def test_returns_value_from_cache(
'app.extensions.RedisClient.set',
)
organisations_client.get_domains()
getattr(organisations_client, client_method)()
assert mock_redis_get.call_args_list == expected_cache_get_calls
assert mock_api_get.call_args_list == expected_api_calls