Skip to content

Commit

Permalink
perf: use read replica or default
Browse files Browse the repository at this point in the history
  • Loading branch information
0x29a committed Dec 30, 2023
1 parent 36a9679 commit 6422e62
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions enterprise/api/v1/views/enterprise_course_enrollment.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@
from enterprise.api.v1 import serializers
from enterprise.api.v1.views.base_views import EnterpriseReadWriteModelViewSet

try:
from common.djangoapps.util.query import read_replica_or_default
except ImportError:
def read_replica_or_default():
return None


class PaginatorWithOptimizedCount(Paginator):
"""
Expand Down Expand Up @@ -67,6 +73,12 @@ class EnterpriseCourseEnrollmentViewSet(EnterpriseReadWriteModelViewSet):

pagination_class = EnterpriseCourseEnrollmentPagination

def get_queryset(self):
queryset = super().get_queryset()
if self.request.method == 'GET':
queryset = queryset.using(read_replica_or_default())
return queryset

def get_serializer_class(self):
"""
Use a special serializer for any requests that aren't read-only.
Expand Down

0 comments on commit 6422e62

Please sign in to comment.