feat: Optimize the querying of course block dates when querying dates for use in a
course outline, which don't need block dates below the subsection level of a course. Pass the course's published version to all the appropriate places where edx-when's API is called - to allow edx-when to more efficiently cache queried/processed results. TNL-8061
This commit is contained in:
committed by
David Ormsbee
parent
e3c83bd86f
commit
cc3747add6
@@ -356,7 +356,7 @@ def _get_user_course_outline_and_processors(course_key: CourseKey, # lint-amnes
|
||||
# particular ordering).
|
||||
processor = processor_cls(course_key, user, at_time)
|
||||
processors[name] = processor
|
||||
processor.load_data()
|
||||
processor.load_data(full_course_outline)
|
||||
if not user_can_see_all_content:
|
||||
# function_trace lets us see how expensive each processor is being.
|
||||
with function_trace(f'learning_sequences.api.outline_processors.{name}'):
|
||||
|
||||
@@ -8,6 +8,8 @@ from datetime import datetime
|
||||
from opaque_keys.edx.keys import CourseKey # lint-amnesty, pylint: disable=unused-import
|
||||
from openedx.core import types
|
||||
|
||||
from ...data import CourseOutlineData
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@@ -44,7 +46,7 @@ class OutlineProcessor:
|
||||
self.user = user
|
||||
self.at_time = at_time
|
||||
|
||||
def load_data(self):
|
||||
def load_data(self, full_course_outline: CourseOutlineData): # pylint: disable=unused-argument
|
||||
"""
|
||||
Fetch whatever data you need about the course and user here.
|
||||
|
||||
@@ -59,7 +61,7 @@ class OutlineProcessor:
|
||||
"""
|
||||
pass # lint-amnesty, pylint: disable=unnecessary-pass
|
||||
|
||||
def inaccessible_sequences(self, full_course_outline): # lint-amnesty, pylint: disable=unused-argument
|
||||
def inaccessible_sequences(self, full_course_outline: CourseOutlineData): # pylint: disable=unused-argument
|
||||
"""
|
||||
Return a set/frozenset of Sequence UsageKeys that are not accessible.
|
||||
|
||||
@@ -68,7 +70,7 @@ class OutlineProcessor:
|
||||
"""
|
||||
return frozenset()
|
||||
|
||||
def usage_keys_to_remove(self, full_course_outline): # lint-amnesty, pylint: disable=unused-argument
|
||||
def usage_keys_to_remove(self, full_course_outline: CourseOutlineData): # pylint: disable=unused-argument
|
||||
"""
|
||||
Return a set/frozenset of UsageKeys to remove altogether.
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ class ContentGatingOutlineProcessor(OutlineProcessor):
|
||||
self.required_content = None
|
||||
self.can_skip_entrance_exam = False
|
||||
|
||||
def load_data(self):
|
||||
def load_data(self, full_course_outline):
|
||||
"""
|
||||
Get the required content for the course, and whether
|
||||
or not the user can skip the entrance exam.
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
# lint-amnesty, pylint: disable=missing-module-docstring
|
||||
import logging
|
||||
from datetime import datetime
|
||||
|
||||
from opaque_keys.edx.keys import CourseKey
|
||||
from openedx.core import types
|
||||
|
||||
from xmodule.partitions.enrollment_track_partition_generator import (
|
||||
create_enrollment_track_partition_with_course_id
|
||||
@@ -22,12 +26,12 @@ class EnrollmentTrackPartitionGroupsOutlineProcessor(OutlineProcessor):
|
||||
significant limitation. Nonetheless, it is a step towards the goal of
|
||||
supporting all partition schemes in the future.
|
||||
"""
|
||||
def __init__(self, course_key, user, at_time):
|
||||
def __init__(self, course_key: CourseKey, user: types.User, at_time: datetime):
|
||||
super().__init__(course_key, user, at_time)
|
||||
self.enrollment_track_groups = {}
|
||||
self.user_group = None
|
||||
|
||||
def load_data(self):
|
||||
def load_data(self, full_course_outline):
|
||||
"""
|
||||
Pull track groups for this course and which group the user is in.
|
||||
"""
|
||||
|
||||
@@ -42,11 +42,16 @@ class ScheduleOutlineProcessor(OutlineProcessor):
|
||||
self._course_end = None
|
||||
self._is_beta_tester = False
|
||||
|
||||
def load_data(self):
|
||||
"""Pull dates information from edx-when."""
|
||||
# (usage_key, 'due'): datetime.datetime(2019, 12, 11, 15, 0, tzinfo=<UTC>)
|
||||
# TODO: Merge https://github.com/edx/edx-when/pull/48 and add `outline_only=True`
|
||||
self.dates = get_dates_for_course(self.course_key, self.user)
|
||||
def load_data(self, full_course_outline):
|
||||
"""
|
||||
Pull dates information from edx-when.
|
||||
|
||||
Return data format: (usage_key, 'due'): datetime.datetime(2019, 12, 11, 15, 0, tzinfo=<UTC>)
|
||||
"""
|
||||
self.dates = get_dates_for_course(
|
||||
self.course_key, self.user, subsection_and_higher_only=True,
|
||||
published_version=full_course_outline.published_version
|
||||
)
|
||||
|
||||
for (usage_key, field_name), date in self.dates.items():
|
||||
self.keys_to_schedule_fields[usage_key][field_name] = date
|
||||
|
||||
@@ -28,7 +28,7 @@ class SpecialExamsOutlineProcessor(OutlineProcessor):
|
||||
"""
|
||||
Responsible for applying all outline processing related to special exams.
|
||||
"""
|
||||
def load_data(self):
|
||||
def load_data(self, full_course_outline):
|
||||
"""
|
||||
Check if special exams are enabled
|
||||
"""
|
||||
|
||||
@@ -1737,8 +1737,10 @@ class EnrollmentTrackPartitionGroupsTestCase(OutlineProcessorTestCase): # lint-
|
||||
|
||||
check_date = datetime(2021, 3, 27, tzinfo=timezone.utc)
|
||||
for learner_to_verify in learners_to_verify:
|
||||
processor = EnrollmentTrackPartitionGroupsOutlineProcessor(self.course_key, learner_to_verify, check_date)
|
||||
processor.load_data()
|
||||
processor = EnrollmentTrackPartitionGroupsOutlineProcessor(
|
||||
self.course_key, learner_to_verify, check_date
|
||||
)
|
||||
processor.load_data(full_outline)
|
||||
removed_usage_keys = processor.usage_keys_to_remove(full_outline)
|
||||
assert len(removed_usage_keys) == expected_values_dict[learner_to_verify.username]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user