From 0ee8c2c14076a0be2a1bceef25dbb946d8650a8f Mon Sep 17 00:00:00 2001 From: HAEKADI Date: Thu, 24 Oct 2024 10:15:17 +0200 Subject: [PATCH] feat: cache siren and siret queries --- app/elastic/es_search_runner.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/app/elastic/es_search_runner.py b/app/elastic/es_search_runner.py index 8eb4eabb..97e05621 100644 --- a/app/elastic/es_search_runner.py +++ b/app/elastic/es_search_runner.py @@ -8,6 +8,8 @@ extract_ul_and_etab_from_es_response, page_through_results, ) +from app.elastic.parsers.siren import is_siren +from app.elastic.parsers.siret import is_siret from app.elastic.text_search import build_es_search_text_query from app.service.search_type import SearchType from app.utils.cache import cache_strategy @@ -114,9 +116,15 @@ def get_es_search_response(): self.execution_time = cached_search_results["execution_time"] def should_cache_search_response(self): - """Cache search response if execution time is higher than 400 ms""" + """Cache search response if execution time is higher than 400 ms + or if the query terms are a siren or siret.""" try: - if self.execution_time > MIN_EXECUTION_TIME: + query_terms = self.search_params.terms + if ( + self.execution_time > MIN_EXECUTION_TIME + or is_siren(query_terms) + or is_siret(query_terms) + ): return True return False except KeyError as error: