diff --git a/lms/djangoapps/course_home_api/outline/views.py b/lms/djangoapps/course_home_api/outline/views.py index 1d02261dbc0c..f116ce1092b6 100644 --- a/lms/djangoapps/course_home_api/outline/views.py +++ b/lms/djangoapps/course_home_api/outline/views.py @@ -56,7 +56,11 @@ get_current_update_for_user ) from openedx.features.course_experience.url_helpers import get_learning_mfe_home_url -from openedx.features.course_experience.utils import get_course_outline_block_tree, get_start_block +from openedx.features.course_experience.utils import ( + get_course_outline_block_tree, + get_course_outline_block_tree_with_cache, + get_start_block +) from openedx.features.discounts.utils import generate_offer_data from xmodule.course_block import COURSE_VISIBILITY_PUBLIC, COURSE_VISIBILITY_PUBLIC_OUTLINE # lint-amnesty, pylint: disable=wrong-import-order @@ -243,7 +247,7 @@ def get(self, request, *args, **kwargs): # pylint: disable=too-many-statements show_enrolled = is_enrolled or is_staff enable_proctored_exams = False if show_enrolled: - course_blocks = get_course_outline_block_tree(request, course_key_string, request.user) + course_blocks = get_course_outline_block_tree_with_cache(request, course_key_string, request.user) date_blocks = get_course_date_blocks(course, request.user, request, num_assignments=1) dates_widget['course_date_blocks'] = [block for block in date_blocks if not isinstance(block, TodaysDate)] @@ -278,7 +282,7 @@ def get(self, request, *args, **kwargs): # pylint: disable=too-many-statements resume_course['url'] = start_block['lms_web_url'] elif allow_public_outline or allow_public or user_is_masquerading: - course_blocks = get_course_outline_block_tree(request, course_key_string, None) + course_blocks = get_course_outline_block_tree_with_cache(request, course_key_string, None) if allow_public or user_is_masquerading: handouts_html = get_course_info_section(request, request.user, course, 'handouts') @@ -416,7 +420,7 @@ class CourseNavigationBlocksView(RetrieveAPIView): serializer_class = CourseBlockSerializer COURSE_BLOCKS_CACHE_KEY_TEMPLATE = ( - 'course_sidebar_blocks_{course_key_string}_{course_version}_{user_id}_{user_cohort_id}' + 'course_sidebar_blocks_{course_key_string}_{course_edited_timestamp}_{user_id}_{user_cohort_id}' '_{enrollment_mode}_{allow_public}_{allow_public_outline}_{is_masquerading}' ) COURSE_BLOCKS_CACHE_TIMEOUT = 60 * 60 # 1 hour @@ -451,7 +455,7 @@ def get(self, request, *args, **kwargs): cache_key = self.COURSE_BLOCKS_CACHE_KEY_TEMPLATE.format( course_key_string=course_key_string, - course_version=str(course.course_version), + course_edited_timestamp=str(course.subtree_edited_on.timestamp()), user_id=request.user.id, enrollment_mode=getattr(enrollment, 'mode', ''), user_cohort_id=getattr(user_cohort, 'id', ''), diff --git a/lms/djangoapps/courseware/toggles.py b/lms/djangoapps/courseware/toggles.py index 4aadfd3e93ed..65e7d4718d91 100644 --- a/lms/djangoapps/courseware/toggles.py +++ b/lms/djangoapps/courseware/toggles.py @@ -68,7 +68,7 @@ f'{WAFFLE_FLAG_NAMESPACE}.mfe_courseware_search', __name__ ) -# .. toggle_name: courseware.navigation_sidebar_blocks_caching +# .. toggle_name: courseware.disable_navigation_sidebar_blocks_caching # .. toggle_implementation: WaffleFlag # .. toggle_default: False # .. toggle_description: Disable caching of navigation sidebar blocks on Learning MFE. diff --git a/openedx/features/course_experience/utils.py b/openedx/features/course_experience/utils.py index 4675d0a974e0..44170cff4998 100644 --- a/openedx/features/course_experience/utils.py +++ b/openedx/features/course_experience/utils.py @@ -15,6 +15,17 @@ @request_cached() +def get_course_outline_block_tree_with_cache(request, course_id, user=None, allow_start_dates_in_future=False): + """ + Returns the root block of the course outline, with children as blocks. + + allow_start_dates_in_future (bool): When True, will allow blocks to be + returned that can bypass the StartDateTransformer's filter to show + blocks with start dates in the future. + """ + return get_course_outline_block_tree(request, course_id, user, allow_start_dates_in_future) + + def get_course_outline_block_tree(request, course_id, user=None, allow_start_dates_in_future=False): # lint-amnesty, pylint: disable=too-many-statements """ Returns the root block of the course outline, with children as blocks.