-
Notifications
You must be signed in to change notification settings - Fork 3
add caching to remaining views #1555
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
f9e7f2f
c049084
4504b80
06f97c3
df77e8e
e6a3ca6
79776fa
f2f8762
6107960
b961904
da13a7e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -91,7 +91,7 @@ | |
| AnonymousAccessReadonlyPermission, | ||
| is_admin_user, | ||
| ) | ||
| from main.utils import chunks | ||
| from main.utils import cache_page_for_all_users, cache_page_for_anonymous_users, chunks | ||
|
|
||
| log = logging.getLogger(__name__) | ||
|
|
||
|
|
@@ -159,6 +159,14 @@ def get_queryset(self) -> QuerySet: | |
| """ | ||
| return self._get_base_queryset().filter(published=True) | ||
|
|
||
| @method_decorator( | ||
| cache_page_for_anonymous_users( | ||
| settings.SEARCH_PAGE_CACHE_DURATION, cache="redis", key_prefix="search" | ||
| ) | ||
| ) | ||
| def list(self, request, *args, **kwargs): | ||
| return super().list(request, *args, **kwargs) | ||
|
|
||
|
|
||
| @extend_schema_view( | ||
| list=extend_schema( | ||
|
|
@@ -508,6 +516,14 @@ def learning_paths(self, request, *args, **kwargs): # noqa: ARG002 | |
| serializer = SerializerClass(current_relationships, many=True) | ||
| return Response(serializer.data) | ||
|
|
||
| @method_decorator( | ||
| cache_page_for_anonymous_users( | ||
| settings.SEARCH_PAGE_CACHE_DURATION, cache="redis", key_prefix="search" | ||
| ) | ||
| ) | ||
| def list(self, request, *args, **kwargs): | ||
| return super().list(request, *args, **kwargs) | ||
|
|
||
|
|
||
| @extend_schema_view( | ||
| create=extend_schema(summary="Learning Path Resource Relationship Add"), | ||
|
|
@@ -533,6 +549,14 @@ class LearningPathItemsViewSet(ResourceListItemsViewSet, viewsets.ModelViewSet): | |
| permission_classes = (permissions.HasLearningPathItemPermissions,) | ||
| http_method_names = VALID_HTTP_METHODS | ||
|
|
||
| @method_decorator( | ||
| cache_page_for_anonymous_users( | ||
| settings.SEARCH_PAGE_CACHE_DURATION, cache="redis", key_prefix="search" | ||
| ) | ||
| ) | ||
| def list(self, request, *args, **kwargs): | ||
| return super().list(request, *args, **kwargs) | ||
|
|
||
| def create(self, request, *args, **kwargs): | ||
| request.data["parent"] = request.data.get("parent_id") | ||
| return super().create(request, *args, **kwargs) | ||
|
|
@@ -568,6 +592,14 @@ class TopicViewSet(viewsets.ReadOnlyModelViewSet): | |
| filter_backends = [DjangoFilterBackend] | ||
| filterset_class = TopicFilter | ||
|
|
||
| @method_decorator( | ||
| cache_page_for_all_users( | ||
| settings.SEARCH_PAGE_CACHE_DURATION, cache="redis", key_prefix="search" | ||
| ) | ||
| ) | ||
| def list(self, request, *args, **kwargs): | ||
| return super().list(request, *args, **kwargs) | ||
|
|
||
|
|
||
| @extend_schema_view( | ||
| list=extend_schema(summary="List"), | ||
|
|
@@ -819,6 +851,14 @@ class ContentTagViewSet(viewsets.ReadOnlyModelViewSet): | |
| pagination_class = LargePagination | ||
| permission_classes = (AnonymousAccessReadonlyPermission,) | ||
|
|
||
| @method_decorator( | ||
| cache_page_for_all_users( | ||
| settings.SEARCH_PAGE_CACHE_DURATION, cache="redis", key_prefix="search" | ||
| ) | ||
| ) | ||
| def list(self, *args, **kwargs): | ||
| return super().list(*args, **kwargs) | ||
|
|
||
|
|
||
| @extend_schema_view( | ||
| list=extend_schema(summary="List"), | ||
|
|
@@ -838,6 +878,14 @@ class DepartmentViewSet(viewsets.ReadOnlyModelViewSet): | |
| lookup_url_kwarg = "department_id" | ||
| lookup_field = "department_id__iexact" | ||
|
|
||
| @method_decorator( | ||
| cache_page_for_all_users( | ||
| settings.SEARCH_PAGE_CACHE_DURATION, cache="redis", key_prefix="search" | ||
| ) | ||
| ) | ||
| def list(self, *args, **kwargs): | ||
| return super().list(*args, **kwargs) | ||
|
|
||
|
|
||
| @extend_schema_view( | ||
| list=extend_schema(summary="List"), | ||
|
|
@@ -853,6 +901,14 @@ class SchoolViewSet(viewsets.ReadOnlyModelViewSet): | |
| pagination_class = LargePagination | ||
| permission_classes = (AnonymousAccessReadonlyPermission,) | ||
|
|
||
| @method_decorator( | ||
| cache_page_for_all_users( | ||
| settings.SEARCH_PAGE_CACHE_DURATION, cache="redis", key_prefix="search" | ||
| ) | ||
| ) | ||
| def list(self, *args, **kwargs): | ||
| return super().list(*args, **kwargs) | ||
|
|
||
|
|
||
| @extend_schema_view( | ||
| list=extend_schema(summary="List"), | ||
|
|
@@ -868,6 +924,14 @@ class PlatformViewSet(viewsets.ReadOnlyModelViewSet): | |
| pagination_class = LargePagination | ||
| permission_classes = (AnonymousAccessReadonlyPermission,) | ||
|
|
||
| @method_decorator( | ||
| cache_page_for_all_users( | ||
| settings.SEARCH_PAGE_CACHE_DURATION, cache="redis", key_prefix="search" | ||
| ) | ||
| ) | ||
| def list(self, *args, **kwargs): | ||
| return super().list(*args, **kwargs) | ||
|
|
||
|
|
||
| @extend_schema_view( | ||
| list=extend_schema(summary="List"), | ||
|
|
@@ -884,6 +948,14 @@ class OfferedByViewSet(viewsets.ReadOnlyModelViewSet): | |
| permission_classes = (AnonymousAccessReadonlyPermission,) | ||
| lookup_field = "code" | ||
|
|
||
| @method_decorator( | ||
| cache_page_for_anonymous_users( | ||
| settings.SEARCH_PAGE_CACHE_DURATION, cache="redis", key_prefix="search" | ||
| ) | ||
| ) | ||
| def list(self, request, *args, **kwargs): | ||
| return super().list(request, *args, **kwargs) | ||
|
|
||
|
|
||
| @extend_schema_view( | ||
| list=extend_schema( | ||
|
|
@@ -994,6 +1066,11 @@ def get_queryset(self) -> QuerySet: | |
| .distinct() | ||
| ) | ||
|
|
||
| @method_decorator( | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was some deliberate results randomization added to this featured list view so as not to give any apparent preference to any particular unit. Might be good to double-check with Ferdi to see if it's okay if that randomization is cached so all anonymous users see the same result for 24 hours before it's randomized again.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. double checked with ferdi. He said we can leave this as-is and have a separate ticket to handle the randomization on the frontend. |
||
| cache_page_for_anonymous_users( | ||
| settings.SEARCH_PAGE_CACHE_DURATION, cache="redis", key_prefix="search" | ||
| ) | ||
| ) | ||
| @extend_schema( | ||
| summary="List", | ||
| description="Get a paginated list of featured resources", | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.