Skip to content

Commit

Permalink
temp: add function_trace on various serializers for additional tracing (
Browse files Browse the repository at this point in the history
#4287)

* temp: add function_trace on various serializers for additional tracing

* chore: rename

* chore: update trace
  • Loading branch information
DawoudSheraz committed Mar 14, 2024
1 parent 3943338 commit 82b7d38
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
7 changes: 7 additions & 0 deletions course_discovery/apps/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from django.utils.text import slugify
from django.utils.translation import gettext_lazy as _
from django_countries.serializer_fields import CountryField
from edx_django_utils.monitoring import function_trace
from localflavor.us.us_states import CONTIGUOUS_STATES
from opaque_keys.edx.locator import CourseLocator
from rest_flex_fields.serializers import FlexFieldsSerializerMixin
Expand Down Expand Up @@ -431,6 +432,7 @@ def get_banner_image_url(self, obj):
return None

@classmethod
@function_trace('organization_serializer_prefetch')
def prefetch_queryset(cls, partner):
return Organization.objects.filter(partner=partner).select_related('partner').prefetch_related('tags')

Expand Down Expand Up @@ -776,6 +778,7 @@ class SeatSerializer(BaseModelSerializer):
bulk_sku = serializers.CharField()

@classmethod
@function_trace('seat_serializer_fetch')
def prefetch_queryset(cls):
return Seat.everything.all().select_related('currency', 'type')

Expand Down Expand Up @@ -924,6 +927,7 @@ class MinimalCourseRunSerializer(FlexFieldsSerializerMixin, TimestampModelSerial
variant_id = serializers.UUIDField(allow_null=True, required=False)

@classmethod
@function_trace('minimal_course_run_serializer_prefetch')
def prefetch_queryset(cls, queryset=None):
# Explicitly check for None to avoid returning all CourseRuns when the
# queryset passed in happens to be empty.
Expand Down Expand Up @@ -1179,6 +1183,7 @@ class MinimalCourseSerializer(FlexFieldsSerializerMixin, TimestampModelSerialize
course_run_statuses = serializers.ReadOnlyField()

@classmethod
@function_trace('minimal_course_serializer_prefetch')
def prefetch_queryset(cls, queryset=None, course_runs=None):
# Explicitly check for None to avoid returning all Courses when the
# queryset passed in happens to be empty.
Expand Down Expand Up @@ -1989,6 +1994,7 @@ def get_organization_logo_override_url(self, obj):
return None

@classmethod
@function_trace('minimal_program_prefetch_trace')
def prefetch_queryset(cls, partner, queryset=None):
# Explicitly check if the queryset is None before selecting related
queryset = queryset if queryset is not None else Program.objects.filter(partner=partner)
Expand Down Expand Up @@ -2295,6 +2301,7 @@ class PathwaySerializer(BaseModelSerializer):
course_run_statuses = serializers.ReadOnlyField()

@classmethod
@function_trace('pathways_program_prefetch')
def prefetch_queryset(cls, partner):
queryset = Pathway.objects.filter(partner=partner)

Expand Down
2 changes: 0 additions & 2 deletions course_discovery/apps/api/v1/views/pathways.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
""" Views for accessing Pathway data """
from edx_django_utils.monitoring import function_trace
from rest_framework import viewsets

from course_discovery.apps.api import serializers
Expand All @@ -11,7 +10,6 @@ class PathwayViewSet(CompressedCacheResponseMixin, viewsets.ReadOnlyModelViewSet
permission_classes = (ReadOnlyByPublisherUser,)
serializer_class = serializers.PathwaySerializer

@function_trace('pathways_api_queryset')
def get_queryset(self):
queryset = self.get_serializer_class().prefetch_queryset(partner=self.request.site.partner)
return queryset.order_by('created')

0 comments on commit 82b7d38

Please sign in to comment.