Skip to content

Commit b955621

Browse files
mumarkhan999M Umar Khan
andauthored
chore: fix cache content size calculation error (#36511)
Co-authored-by: M Umar Khan <umar.khan@A006-01609.local>
1 parent 0acc44f commit b955621

File tree

2 files changed

+6
-4
lines changed
  • lms/djangoapps/courseware
  • openedx/core/djangoapps/content/block_structure

2 files changed

+6
-4
lines changed

lms/djangoapps/courseware/courses.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -795,10 +795,11 @@ def get_assignments_grades(user, course_id, cache_timeout):
795795
collected_block_structure = get_block_structure_manager(course_id).get_collected()
796796

797797
total_bytes_in_one_mb = 1024 * 1024
798-
data_size_in_mbs = round(len(pickle.dumps(collected_block_structure)) / total_bytes_in_one_mb, 2)
799-
if data_size_in_mbs < total_bytes_in_one_mb * 2:
798+
data_size_in_bytes = len(pickle.dumps(collected_block_structure))
799+
if data_size_in_bytes < total_bytes_in_one_mb * 2:
800800
cache.set(cache_key, collected_block_structure, cache_timeout)
801801
else:
802+
data_size_in_mbs = round(data_size_in_bytes / total_bytes_in_one_mb, 2)
802803
# .. custom_attribute_name: collected_block_structure_size_in_mbs
803804
# .. custom_attribute_description: contains the data chunk size in MBs. The size on which
804805
# the memcached client failed to store value in cache.

openedx/core/djangoapps/content/block_structure/store.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,9 @@ def _add_to_cache(self, serialized_data, bs_model):
137137
"""
138138
cache_key = self._encode_root_cache_key(bs_model)
139139
total_bytes_in_one_mb = 1024 * 1024
140-
data_size_in_mbs = round(len(serialized_data) / total_bytes_in_one_mb, 2)
141-
if data_size_in_mbs < total_bytes_in_one_mb * 2:
140+
data_size_in_bytes = len(serialized_data)
141+
data_size_in_mbs = round(data_size_in_bytes / total_bytes_in_one_mb, 2)
142+
if data_size_in_bytes < total_bytes_in_one_mb * 2:
142143
self._cache.set(cache_key, serialized_data, timeout=config.cache_timeout_in_seconds())
143144
logger.info("BlockStructure: Added to cache; %s, size: %.2fMB", bs_model, data_size_in_mbs)
144145
else:

0 commit comments

Comments
 (0)