From 19cf32d3466771c0b489b1efddb2f6345eeaf95f Mon Sep 17 00:00:00 2001 From: Ivo Branco Date: Thu, 4 May 2023 14:11:41 +0000 Subject: [PATCH] Use read replica db for course enrollment admin Use `read_replica` Open edX database to search course enrollments. GN-1145 --- nau_openedx_extensions/student/admin.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/nau_openedx_extensions/student/admin.py b/nau_openedx_extensions/student/admin.py index 746035e..d8912e8 100644 --- a/nau_openedx_extensions/student/admin.py +++ b/nau_openedx_extensions/student/admin.py @@ -10,6 +10,7 @@ CourseAccessRole, CourseEnrollment, ) +from common.djangoapps.util.query import use_read_replica_if_available # lint-amnesty, pylint: disable=import-error from django.contrib import admin from nau_openedx_extensions.utils.admin import ExportCsvMixin @@ -59,7 +60,9 @@ def openedx_email(self, instance): # Changes from upstream: # - remove the custom order by / sort; # - remove the select_related user; +# - search only if search term has minimum 3 characters length; # - change search by user username or email; +# - use `read_replica` database if available for search; @admin.register(CourseEnrollment) class NAUCourseEnrollmentAdmin(DisableEnrollmentAdminMixin, admin.ModelAdmin): """ @@ -80,4 +83,4 @@ def get_search_results(self, request, queryset, search_term): qs, use_distinct = super().get_search_results(request, queryset, search_term) if not search_term or len(search_term) < 3: qs = CourseEnrollment.objects.none() - return qs, use_distinct + return use_read_replica_if_available(qs), use_distinct