chore: use pickle to compute collected_blocksture size before cacheing (#36455)

Co-authored-by: M Umar Khan <umar.khan@A006-01609.local>
This commit is contained in:
Muhammad Umar Khan
2025-03-27 21:01:25 +05:00
committed by GitHub
parent 5e61a1d959
commit c6f75dfd2e

View File

@@ -4,6 +4,7 @@ courseware.
"""
import logging
import pickle
from collections import defaultdict, namedtuple
from datetime import datetime
@@ -59,7 +60,7 @@ from openedx.core.djangoapps.content.course_overviews.models import CourseOvervi
from openedx.core.djangoapps.enrollments.api import get_course_enrollment_details
from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers
from openedx.core.lib.api.view_utils import LazySequence
from openedx.core.lib.cache_utils import request_cached, zpickle
from openedx.core.lib.cache_utils import request_cached
from openedx.core.lib.courses import get_course_by_id
from openedx.features.course_duration_limits.access import AuditExpiredError
from openedx.features.course_experience import RELATIVE_DATES_FLAG
@@ -794,7 +795,7 @@ 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(zpickle(collected_block_structure)) / total_bytes_in_one_mb, 2)
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:
cache.set(cache_key, collected_block_structure, cache_timeout)
else: