Skip to content

Commit

Permalink
refactor: [AXIMST-790] Make waffle flag to disable cache, instead of …
Browse files Browse the repository at this point in the history
…enabling
  • Loading branch information
NiedielnitsevIvan committed Apr 11, 2024
1 parent 779c01f commit 8dab7a2
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
3 changes: 1 addition & 2 deletions lms/djangoapps/course_home_api/outline/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
11 changes: 6 additions & 5 deletions lms/djangoapps/course_home_api/outline/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -459,18 +459,19 @@ 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):
course_blocks = get_course_outline_block_tree(request, course_key_string, request.user)
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)
Expand Down
16 changes: 9 additions & 7 deletions lms/djangoapps/courseware/toggles.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

0 comments on commit 8dab7a2

Please sign in to comment.