From 980f18359f7e4c609fff5a2c1d334259e3d7f758 Mon Sep 17 00:00:00 2001 From: Alejandro Cardenas Date: Fri, 20 May 2022 22:29:01 +0100 Subject: [PATCH 1/3] feat: add lms setting to set mfe config cache --- lms/envs/common.py | 6 ++++++ openedx/core/djangoapps/mfe_api/views.py | 8 ++++++++ 2 files changed, 14 insertions(+) diff --git a/lms/envs/common.py b/lms/envs/common.py index f6d77d904ba9..888abbacea49 100644 --- a/lms/envs/common.py +++ b/lms/envs/common.py @@ -4872,6 +4872,12 @@ def _make_locale_paths(settings): # pylint: disable=missing-function-docstring ENABLE_AUTHN_LOGIN_BLOCK_HIBP_POLICY = False HIBP_LOGIN_BLOCK_PASSWORD_FREQUENCY_THRESHOLD = 5 +# .. setting_name: MFE_CONFIG_API_CACHE_TIMEOUT +# .. setting_default: 60*5 +# .. setting_description: The MFE_CONFIG site configuration will be cached during the +# specified time +MFE_CONFIG_API_CACHE_TIMEOUT = 60*5 + ############### Settings for the ace_common plugin ################# ACE_ENABLED_CHANNELS = ['django_email'] ACE_ENABLED_POLICIES = ['bulk_email_optout'] diff --git a/openedx/core/djangoapps/mfe_api/views.py b/openedx/core/djangoapps/mfe_api/views.py index 6cd15d3c84a7..01bd776f1b17 100644 --- a/openedx/core/djangoapps/mfe_api/views.py +++ b/openedx/core/djangoapps/mfe_api/views.py @@ -9,6 +9,14 @@ class MFEConfigView(APIView): Provides an API endpoint for MFE config from site configurations. """ + @method_decorator( + cache_page( + configuration_helpers.get_value( + "MFE_CONFIG_API_CACHE_TIMEOUT", + settings.MFE_CONFIG_API_CACHE_TIMEOUT + ) + ) + ) def get(self, request): """ GET /api/mfe/v1/config From 3a856e684d8ff2f36851660a093c8102fa94c77d Mon Sep 17 00:00:00 2001 From: Alejandro Cardenas Date: Fri, 20 May 2022 22:34:00 +0100 Subject: [PATCH 2/3] fix: solve missing imports --- openedx/core/djangoapps/mfe_api/views.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/openedx/core/djangoapps/mfe_api/views.py b/openedx/core/djangoapps/mfe_api/views.py index 01bd776f1b17..92b21369eb4c 100644 --- a/openedx/core/djangoapps/mfe_api/views.py +++ b/openedx/core/djangoapps/mfe_api/views.py @@ -1,3 +1,7 @@ +from django.conf import settings +from django.utils.decorators import method_decorator +from django.views.decorators.cache import cache_page + from rest_framework.response import Response from rest_framework.views import APIView From d741b7653edec177e5a7a3013abf0fcc08401d0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Fernanda=20Magallanes=20Z?= Date: Fri, 20 May 2022 18:09:17 -0400 Subject: [PATCH 3/3] fix: only set cache timeout with settings --- openedx/core/djangoapps/mfe_api/views.py | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/openedx/core/djangoapps/mfe_api/views.py b/openedx/core/djangoapps/mfe_api/views.py index 92b21369eb4c..c046bb2c509a 100644 --- a/openedx/core/djangoapps/mfe_api/views.py +++ b/openedx/core/djangoapps/mfe_api/views.py @@ -13,14 +13,7 @@ class MFEConfigView(APIView): Provides an API endpoint for MFE config from site configurations. """ - @method_decorator( - cache_page( - configuration_helpers.get_value( - "MFE_CONFIG_API_CACHE_TIMEOUT", - settings.MFE_CONFIG_API_CACHE_TIMEOUT - ) - ) - ) + @method_decorator(cache_page(settings.MFE_CONFIG_API_CACHE_TIMEOUT)) def get(self, request): """ GET /api/mfe/v1/config