Skip to content

Commit

Permalink
feat: cache siren and siret queries
Browse files Browse the repository at this point in the history
  • Loading branch information
HAEKADI committed Oct 24, 2024
1 parent 2169409 commit 0ee8c2c
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions app/elastic/es_search_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 0ee8c2c

Please sign in to comment.