Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/signal_documentation/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,8 @@
}
}

CACHE_TIME = int(os.environ.get('CACHE_TIME', 60 * 60 * 24)) # 24 hours


# Celery
# https://docs.celeryq.dev/en/stable/index.html
Expand Down
2 changes: 1 addition & 1 deletion src/signals/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class SignalSerializer(ModelSerializer):

links = LinkSerializer(many=True)
pathogen = SlugRelatedField(many=True, read_only=True, slug_field='name')
signal_type = SlugRelatedField(many=True, read_only=True, slug_field='name')
signal_type = SlugRelatedField(read_only=True, slug_field='name')
available_geography = SlugRelatedField(many=True, read_only=True, slug_field='name')
category = SlugRelatedField(read_only=True, slug_field='name')
source = SlugRelatedField(read_only=True, slug_field='name')
Expand Down
4 changes: 3 additions & 1 deletion src/signals/urls.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
from django.urls import path
from django.urls.resolvers import URLPattern
from django.views.decorators.cache import cache_page

from signals.views import (
SignalsDetailView,
SignalsListApiView,
SignalsListView,
)
from signal_documentation.settings import CACHE_TIME

urlpatterns: list[URLPattern] = [
path('', SignalsListView.as_view(), name='signals'),
path('', cache_page(CACHE_TIME)(SignalsListView.as_view()), name='signals'),
path('signals/<int:pk>/', SignalsDetailView.as_view(), name='signal'),
path('signals/<pk>/', SignalsDetailView.as_view(), name='signal'),

Expand Down
12 changes: 11 additions & 1 deletion src/signals/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,17 @@ def get_context_data(self, **kwargs) -> Dict[str, Any]:
context["url_params_str"] = url_params_str
context["filter"] = SignalFilter(self.request.GET, queryset=self.get_queryset())

context["signals"] = self.get_queryset()
context["signals"] = self.get_queryset().prefetch_related(
"pathogen",
"available_geography",
"geographic_scope",
"source",
).select_related(
"base",
"signal_type",
"category",
"license"
)
return context


Expand Down