Commit 6b9e9b3c authored by David Mendez's avatar David Mendez
Browse files

Allow to set a cache key suffix to ease cache reset

parent 5928449a
......@@ -42,7 +42,6 @@ def get_es_data(index_name, raw_es_query, raw_context, raw_contextual_sort_data)
context_dict = json.loads(raw_context)
context_type = context_dict['context_type']
if context_type in ['TO_COMPOUNDS', 'TO_TARGETS']:
context = context_loader.get_search_by_ids_context(context_dict)
subset_index_name = context['subset_index_name']
es_query = json.loads(raw_es_query)
......@@ -53,7 +52,6 @@ def get_es_data(index_name, raw_es_query, raw_context, raw_contextual_sort_data)
}
return response
es_response, metadata = get_items_with_context(index_name, raw_es_query, raw_context, raw_contextual_sort_data)
response = {
......
......@@ -105,6 +105,8 @@ if RUN_CONFIG.get('es_mappings_cache_seconds') is None:
if RUN_CONFIG.get('filter_query_max_clauses') is None:
RUN_CONFIG['filter_query_max_clauses'] = 30000
RUN_CONFIG['cache_key_suffix'] = RUN_CONFIG.get('cache_key_suffix', 10)
DELAYED_JOBS_CONFIG = RUN_CONFIG.get('delayed_jobs', {})
DEFAULT_DELAYED_JOBS_CONFIG = {
'wwwdev.ebi.ac.uk': 'wwwdev.ebi.ac.uk',
......
......@@ -179,7 +179,7 @@ def get_es_query_cache_key(index_name, es_query):
"""
es_request_digest = get_es_request_digest(es_query)
return f'{index_name}-{es_request_digest}'
return f'{index_name}-{es_request_digest}-{RUN_CONFIG.get("cache_key_suffix")}'
def get_multisearch_cache_key(body):
......@@ -192,7 +192,7 @@ def get_multisearch_cache_key(body):
body_digest = hashlib.sha256(stable_raw_body.encode('utf-8')).digest()
base64_hash = base64.b64encode(body_digest).decode('utf-8')
return f'multisearch-{base64_hash}'
return f'multisearch-{base64_hash}-{RUN_CONFIG.get("cache_key_suffix")}'
def get_es_request_digest(es_query):
......
......@@ -9,6 +9,7 @@ import base64
from app.es_data import es_data
from app.cache import CACHE
from app import create_app
from app.config import RUN_CONFIG
class TestESData(unittest.TestCase):
......@@ -84,7 +85,8 @@ class TestESData(unittest.TestCase):
search_data_digest = hashlib.sha256(stable_raw_search_data.encode('utf-8')).digest()
base64_search_data_hash = base64.b64encode(search_data_digest).decode('utf-8')
cache_key_must_be = "{}-{}".format(es_index, base64_search_data_hash)
cache_key_must_be = f"{es_index}-{base64_search_data_hash}-{RUN_CONFIG.get('cache_key_suffix')}"
cache_key_got = es_data.get_es_query_cache_key(es_index, es_query)
self.assertEqual(cache_key_got, cache_key_must_be, msg='The cache key was not generated correctly!')
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment