Skip to content

Commit

Permalink
refactor: [AXM-40] refactor enrollment caching optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
NiedielnitsevIvan committed Mar 22, 2024
1 parent b943e60 commit 22982df
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
22 changes: 12 additions & 10 deletions lms/djangoapps/mobile_api/users/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ class UserCourseEnrollmentsList(generics.ListAPIView):
certified).
* url: URL to the downloadable version of the certificate, if exists.
"""
queryset = CourseEnrollment.objects.all().select_related('course', 'user')

lookup_field = 'username'

# In Django Rest Framework v3, there is a default pagination
Expand Down Expand Up @@ -353,9 +353,16 @@ def get_serializer_class(self):
return CourseEnrollmentSerializerv05
return CourseEnrollmentSerializer

@cached_property
def queryset(self):
return CourseEnrollment.objects.all().select_related('course', 'user').filter(
user__username=self.kwargs['username'],
is_active=True
).order_by('created').reverse()

def get_queryset(self):
api_version = self.kwargs.get('api_version')
mobile_available = self.mobile_available_enrollments
mobile_available = self.get_mobile_available_enrollments()

not_duration_limited = (
enrollment for enrollment in mobile_available
Expand All @@ -374,19 +381,14 @@ def get_queryset(self):
# return all courses, with associated expiration
return mobile_available

@cached_property
def mobile_available_enrollments(self) -> List[Optional[CourseEnrollment]]:
def get_mobile_available_enrollments(self) -> List[Optional[CourseEnrollment]]:
"""
Gets list with `CourseEnrollment` for mobile available courses.
"""
enrollments = self.queryset.filter(
user__username=self.kwargs['username'],
is_active=True
).order_by('created').reverse()
org = self.request.query_params.get('org', None)

same_org = (
enrollment for enrollment in enrollments
enrollment for enrollment in self.queryset
if enrollment.course_overview and self.is_org(org, enrollment.course_overview.org)
)
mobile_available = (
Expand Down Expand Up @@ -421,7 +423,7 @@ def get_primary_enrollment_by_latest_enrollment_or_progress(self) -> Optional[Co
"""
Gets primary enrollment obj by latest enrollment or latest progress on the course.
"""
mobile_available = self.mobile_available_enrollments
mobile_available = self.get_mobile_available_enrollments()
if not mobile_available:
return None

Expand Down
8 changes: 3 additions & 5 deletions openedx/core/djangoapps/theming/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,9 @@ def converter(matchobj):
This requires figuring out which files the matched URL resolves
to and calling the url() method of the storage.
"""
matched, url = matchobj.groups()
#matches = matchobj.groupdict()
# matched = matches["matched"]
# url = matches["url"]

matches = matchobj.groupdict()
matched = matches["matched"]
url = matches["url"]

# Ignore absolute/protocol-relative and data-uri URLs.
if re.match(r"^[a-z]+:", url):
Expand Down

0 comments on commit 22982df

Please sign in to comment.