diff --git a/lms/djangoapps/courseware/courses.py b/lms/djangoapps/courseware/courses.py index 62bd6bf5c982..5dc4a7ce9107 100644 --- a/lms/djangoapps/courseware/courses.py +++ b/lms/djangoapps/courseware/courses.py @@ -795,10 +795,11 @@ def get_assignments_grades(user, course_id, cache_timeout): collected_block_structure = get_block_structure_manager(course_id).get_collected() total_bytes_in_one_mb = 1024 * 1024 - data_size_in_mbs = round(len(pickle.dumps(collected_block_structure)) / total_bytes_in_one_mb, 2) - if data_size_in_mbs < total_bytes_in_one_mb * 2: + data_size_in_bytes = len(pickle.dumps(collected_block_structure)) + if data_size_in_bytes < total_bytes_in_one_mb * 2: cache.set(cache_key, collected_block_structure, cache_timeout) else: + data_size_in_mbs = round(data_size_in_bytes / total_bytes_in_one_mb, 2) # .. 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. diff --git a/openedx/core/djangoapps/content/block_structure/store.py b/openedx/core/djangoapps/content/block_structure/store.py index 409dae988e92..bb6359b9d3a3 100644 --- a/openedx/core/djangoapps/content/block_structure/store.py +++ b/openedx/core/djangoapps/content/block_structure/store.py @@ -137,8 +137,9 @@ def _add_to_cache(self, serialized_data, bs_model): """ cache_key = self._encode_root_cache_key(bs_model) total_bytes_in_one_mb = 1024 * 1024 - data_size_in_mbs = round(len(serialized_data) / total_bytes_in_one_mb, 2) - if data_size_in_mbs < total_bytes_in_one_mb * 2: + data_size_in_bytes = len(serialized_data) + data_size_in_mbs = round(data_size_in_bytes / total_bytes_in_one_mb, 2) + if data_size_in_bytes < total_bytes_in_one_mb * 2: self._cache.set(cache_key, serialized_data, timeout=config.cache_timeout_in_seconds()) logger.info("BlockStructure: Added to cache; %s, size: %.2fMB", bs_model, data_size_in_mbs) else: