diff --git a/lms/djangoapps/courseware/courses.py b/lms/djangoapps/courseware/courses.py index 0ff6a11a62..f239c8052e 100644 --- a/lms/djangoapps/courseware/courses.py +++ b/lms/djangoapps/courseware/courses.py @@ -16,7 +16,7 @@ from django.core.cache import cache from django.http import Http404, QueryDict from django.urls import reverse from django.utils.translation import gettext as _ -from edx_django_utils.monitoring import function_trace +from edx_django_utils.monitoring import function_trace, set_custom_attribute from fs.errors import ResourceNotFound from opaque_keys.edx.keys import UsageKey from path import Path as path @@ -792,7 +792,16 @@ def get_assignments_grades(user, course_id, cache_timeout): collected_block_structure = cache.get(cache_key) if not collected_block_structure: collected_block_structure = get_block_structure_manager(course_id).get_collected() - cache.set(cache_key, collected_block_structure, cache_timeout) + + total_bytes_in_one_mb = 1024 * 1024 + data_size_in_mbs = round(len(collected_block_structure) / total_bytes_in_one_mb, 2) + if data_size_in_mbs < total_bytes_in_one_mb * 2: + cache.set(cache_key, collected_block_structure, cache_timeout) + else: + # .. custom_attribute_name: collected_block_structure_size_in_mbs + # .. custom_attribute_description: contains the data chunk size in MBs. The size on which + # the memcached client failed to store value in cache. + set_custom_attribute('collected_block_structure_size_in_mbs', data_size_in_mbs) course_grade = CourseGradeFactory().read(user, collected_block_structure=collected_block_structure)