Skip to content
Snippets Groups Projects
Commit bdee9fe4 authored by Antoine Lambert's avatar Antoine Lambert
Browse files

common/utils: Use cache in origin_visit_types function

That function is used to dynamically retrieve the list of origin visit
types (git, svn, npm, ...) currently supported by Software Heritage.

That list of visit types is then used to populate the visit type
dropdown in the search form available in the home and search pages
of the web application.

However getting that visit types list is costly as it involves sending
an elasticsearch query through the use of swh-search.

So instead of sending that costly query each time a search form must
be rendered, prefer to cache the visit types list and update it
every 24 hours.

That change significantly speedup the homepage rendering of the
web application.
parent b364c93d
No related branches found
Tags v5.7.3
No related merge requests found
......@@ -499,14 +499,19 @@ def get_deposit_raw_metadata(deposit_id: int) -> Optional[str]:
return requests.get(url).json()["raw_metadata"]
_origin_visit_types_cache_timeout = 24 * 60 * 60 # 24 hours
@django_cache(
timeout=_origin_visit_types_cache_timeout,
catch_exception=True,
exception_return_value=[],
)
def origin_visit_types() -> List[str]:
"""Return the exhaustive list of visit types for origins
ingested into the archive.
"""
try:
return sorted(search().visit_types_count().keys())
except Exception:
return []
return sorted(search().visit_types_count().keys())
def redirect_to_new_route(request, new_route, permanent=True):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment