Page Menu
Home
Software Heritage
Search
Configure Global Search
Log In
Files
F7123646
D8487.id30574.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Subscribers
None
D8487.id30574.diff
View Options
diff --git a/swh/web/browse/urls.py b/swh/web/browse/urls.py
--- a/swh/web/browse/urls.py
+++ b/swh/web/browse/urls.py
@@ -16,7 +16,7 @@
import swh.web.browse.views.release # noqa
import swh.web.browse.views.revision # noqa
import swh.web.browse.views.snapshot # noqa
-from swh.web.utils import origin_visit_types, reverse
+from swh.web.utils import is_swh_web_production, origin_visit_types, reverse
def _browse_help_view(request: HttpRequest) -> HttpResponse:
@@ -31,7 +31,7 @@
"browse-search.html",
{
"heading": "Search software origins to browse",
- "visit_types": origin_visit_types(),
+ "visit_types": origin_visit_types(use_cache=is_swh_web_production(request)),
},
)
diff --git a/swh/web/utils/__init__.py b/swh/web/utils/__init__.py
--- a/swh/web/utils/__init__.py
+++ b/swh/web/utils/__init__.py
@@ -497,16 +497,25 @@
_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]:
+def origin_visit_types(use_cache: bool = True) -> List[str]:
"""Return the exhaustive list of visit types for origins
ingested into the archive.
+
+ Args:
+ use_cache: if :const:`True`, store visit types in django
+ cache for 24 hours.
"""
- return sorted(search().visit_types_count().keys())
+
+ @django_cache(
+ timeout=_origin_visit_types_cache_timeout,
+ catch_exception=True,
+ exception_return_value=[],
+ invalidate_cache_pred=lambda val: not use_cache,
+ )
+ def _origin_visit_types_internal() -> List[str]:
+ return sorted(search().visit_types_count().keys())
+
+ return _origin_visit_types_internal()
def redirect_to_new_route(request, new_route, permanent=True):
diff --git a/swh/web/webapp/urls.py b/swh/web/webapp/urls.py
--- a/swh/web/webapp/urls.py
+++ b/swh/web/webapp/urls.py
@@ -16,7 +16,7 @@
from django.views.generic.base import RedirectView
from swh.web.config import get_config
-from swh.web.utils import archive, origin_visit_types
+from swh.web.utils import archive, is_swh_web_production, origin_visit_types
from swh.web.utils.exc import sentry_capture_exception
swh_web_config = get_config()
@@ -29,7 +29,11 @@
def default_view(request):
- return render(request, "homepage.html", {"visit_types": origin_visit_types()})
+ return render(
+ request,
+ "homepage.html",
+ {"visit_types": origin_visit_types(use_cache=is_swh_web_production(request))},
+ )
def stat_counters(request):
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Dec 19 2024, 4:20 PM (11 w, 4 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3218482
Attached To
D8487: utils: Cache origin visit types in production webapp only
Event Timeline
Log In to Comment