From 771da541b17e67cad998eede556053565006ca91 Mon Sep 17 00:00:00 2001 From: Ali Akbar <52413434+Ali-D-Akbar@users.noreply.github.com> Date: Thu, 19 Dec 2024 08:02:11 +0500 Subject: [PATCH] perf: use select_related to fetch types in CSVLoader (#4518) --- .../apps/course_metadata/data_loaders/csv_loader.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/course_discovery/apps/course_metadata/data_loaders/csv_loader.py b/course_discovery/apps/course_metadata/data_loaders/csv_loader.py index 0474333bf8..325ff4bbdf 100644 --- a/course_discovery/apps/course_metadata/data_loaders/csv_loader.py +++ b/course_discovery/apps/course_metadata/data_loaders/csv_loader.py @@ -166,7 +166,7 @@ def ingest(self): # pylint: disable=too-many-statements continue course_key = self.get_course_key(org_key, row['number']) - course = Course.objects.filter_drafts(key=course_key, partner=self.partner).first() + course = Course.objects.filter_drafts(key=course_key, partner=self.partner).select_related('type').first() is_course_created = False is_course_run_created = False course_run_restriction = ( @@ -201,8 +201,8 @@ def ingest(self): # pylint: disable=too-many-statements self._register_ingestion_error(CSVIngestionErrors.COURSE_CREATE_ERROR, error_message) continue - course = Course.everything.get(key=course_key, partner=self.partner) - course_run = CourseRun.everything.filter(course=course).first() + course = Course.everything.select_related('type').get(key=course_key, partner=self.partner) + course_run = CourseRun.everything.select_related('type').filter(course=course).first() is_course_created = True is_course_run_created = True