From 8dab7a2d66102ff5b687ef8eb7d0fc6acbf0d012 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=86=D0=B2=D0=B0=D0=BD=20=D0=9D=D1=94=D0=B4=D1=94=D0=BB?= =?UTF-8?q?=D1=8C=D0=BD=D1=96=D1=86=D0=B5=D0=B2?= Date: Thu, 11 Apr 2024 16:09:13 +0300 Subject: [PATCH] refactor: [AXIMST-790] Make waffle flag to disable cache, instead of enabling --- .../course_home_api/outline/serializers.py | 3 +-- lms/djangoapps/course_home_api/outline/views.py | 11 ++++++----- lms/djangoapps/courseware/toggles.py | 16 +++++++++------- 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/lms/djangoapps/course_home_api/outline/serializers.py b/lms/djangoapps/course_home_api/outline/serializers.py index 7dd3ae66daa5..b5e2a488b78c 100644 --- a/lms/djangoapps/course_home_api/outline/serializers.py +++ b/lms/djangoapps/course_home_api/outline/serializers.py @@ -85,8 +85,7 @@ def get_vertical_icon_class(block): for higher_class in icon_call_priority: if higher_class in child_classes: new_class = higher_class - # if 'openassessment' in child_classes: - # new_class = 'fa-pencil-square-o' + return new_class diff --git a/lms/djangoapps/course_home_api/outline/views.py b/lms/djangoapps/course_home_api/outline/views.py index 1c79656182eb..1d02261dbc0c 100644 --- a/lms/djangoapps/course_home_api/outline/views.py +++ b/lms/djangoapps/course_home_api/outline/views.py @@ -40,7 +40,7 @@ from lms.djangoapps.courseware.courses import get_course_date_blocks, get_course_info_section from lms.djangoapps.courseware.date_summary import TodaysDate from lms.djangoapps.courseware.masquerade import is_masquerading, setup_masquerade -from lms.djangoapps.courseware.toggles import courseware_mfe_navigation_sidebar_blocks_caching_is_enabled +from lms.djangoapps.courseware.toggles import courseware_disable_navigation_sidebar_blocks_caching from lms.djangoapps.courseware.views.views import get_cert_data from lms.djangoapps.grades.course_grade_factory import CourseGradeFactory from lms.djangoapps.utils import OptimizelyClient @@ -459,10 +459,11 @@ def get(self, request, *args, **kwargs): allow_public_outline=allow_public_outline, is_masquerading=user_is_masquerading, ) - if courseware_mfe_navigation_sidebar_blocks_caching_is_enabled(): - course_blocks = cache.get(cache_key) - else: + + if navigation_sidebar_caching_is_disabled := courseware_disable_navigation_sidebar_blocks_caching(): course_blocks = None + else: + course_blocks = cache.get(cache_key) if not course_blocks: if getattr(enrollment, 'is_active', False) or bool(staff_access): @@ -470,7 +471,7 @@ def get(self, request, *args, **kwargs): elif allow_public_outline or allow_public or user_is_masquerading: course_blocks = get_course_outline_block_tree(request, course_key_string, None) - if courseware_mfe_navigation_sidebar_blocks_caching_is_enabled(): + if not navigation_sidebar_caching_is_disabled: cache.set(cache_key, course_blocks, self.COURSE_BLOCKS_CACHE_TIMEOUT) course_blocks = self.filter_inaccessible_blocks(course_blocks, course_key) diff --git a/lms/djangoapps/courseware/toggles.py b/lms/djangoapps/courseware/toggles.py index ba319ca98928..4aadfd3e93ed 100644 --- a/lms/djangoapps/courseware/toggles.py +++ b/lms/djangoapps/courseware/toggles.py @@ -71,14 +71,16 @@ # .. toggle_name: courseware.navigation_sidebar_blocks_caching # .. toggle_implementation: WaffleFlag # .. toggle_default: False -# .. toggle_description: Enable caching of navigation sidebar blocks on Learning MFE to improve performance. +# .. toggle_description: Disable caching of navigation sidebar blocks on Learning MFE. +# It can be used when caching the structure of large courses for a large number of users +# at the same time can overload the cache storage (memcache or redis). # .. toggle_use_cases: temporary # .. toggle_creation_date: 2024-03-21 # .. toggle_target_removal_date: None -# .. toggle_tickets: AXIMST-682 +# .. toggle_tickets: FC-0056 # .. toggle_warning: None. -COURSEWARE_MICROFRONTEND_NAVIGATION_SIDEBAR_BLOCKS_CACHING_ENABLED = CourseWaffleFlag( - f'{WAFFLE_FLAG_NAMESPACE}.navigation_sidebar_blocks_caching', __name__ +COURSEWARE_MICROFRONTEND_NAVIGATION_SIDEBAR_BLOCKS_DISABLE_CACHING = CourseWaffleFlag( + f'{WAFFLE_FLAG_NAMESPACE}.disable_navigation_sidebar_blocks_caching', __name__ ) # .. toggle_name: courseware.disable_navigation_sidebar @@ -228,8 +230,8 @@ def courseware_show_default_right_sidebar_is_enabled(course_key=None): return COURSEWARE_SHOW_DEFAULT_RIGHT_SIDEBAR.is_enabled(course_key) -def courseware_mfe_navigation_sidebar_blocks_caching_is_enabled(course_key=None): +def courseware_disable_navigation_sidebar_blocks_caching(course_key=None): """ - Return whether the courseware.navigation_sidebar_blocks_caching flag is on. + Return whether the courseware.disable_navigation_sidebar_blocks_caching flag is on. """ - return COURSEWARE_MICROFRONTEND_NAVIGATION_SIDEBAR_BLOCKS_CACHING_ENABLED.is_enabled(course_key) + return COURSEWARE_MICROFRONTEND_NAVIGATION_SIDEBAR_BLOCKS_DISABLE_CACHING.is_enabled(course_key)