diff --git a/SAS/TMSS/src/tmss/tmssapp/viewsets/scheduling.py b/SAS/TMSS/src/tmss/tmssapp/viewsets/scheduling.py index 601321cf92d003f606c7d9d32afb5c32020b970e..daef6c16b20dc08a4155d7e3a4fe21c72fc18d7e 100644 --- a/SAS/TMSS/src/tmss/tmssapp/viewsets/scheduling.py +++ b/SAS/TMSS/src/tmss/tmssapp/viewsets/scheduling.py @@ -144,7 +144,8 @@ class SubtaskViewSet(LOFARViewSet): filter_class = SubTaskFilter ordering = ('start_time',) - queryset = queryset.prefetch_related('state') + # performance boost: select the related models in a single db call. + queryset = queryset.select_related('state', 'specifications_template', 'specifications_template__type', 'schedule_method', 'cluster', 'created_or_updated_by_user') @swagger_auto_schema(auto_schema=TextPlainAutoSchema, responses={200: 'A LOFAR parset for this subtask (as plain text)', @@ -248,6 +249,9 @@ class SubtaskNestedViewSet(LOFARNestedViewSet): filter_class = SubTaskFilter ordering = ('start_time',) + # performance boost: select the related models in a single db call. + queryset = queryset.select_related('state', 'specifications_template', 'specifications_template__type', 'schedule_method', 'cluster', 'created_or_updated_by_user') + def get_queryset(self): if 'task_blueprint_id' in self.kwargs: task_blueprint = get_object_or_404(models.TaskBlueprint, pk=self.kwargs['task_blueprint_id']) diff --git a/SAS/TMSS/src/tmss/tmssapp/viewsets/specification.py b/SAS/TMSS/src/tmss/tmssapp/viewsets/specification.py index 2a7263a3b1c21ca8ca24aafcd8029575215ef02e..f4f1e95ddbe38152855429597c6360be6448e4dc 100644 --- a/SAS/TMSS/src/tmss/tmssapp/viewsets/specification.py +++ b/SAS/TMSS/src/tmss/tmssapp/viewsets/specification.py @@ -318,6 +318,10 @@ class SchedulingUnitDraftViewSet(LOFARViewSet): .select_related('copy_reason') \ .select_related('scheduling_set') + # use select_related for forward related references + queryset = queryset.select_related('copy_reason', 'scheduling_set', 'requirements_template', 'observation_strategy_template', 'scheduling_constraints_template') + + @swagger_auto_schema(responses={201: 'The Created SchedulingUnitBlueprint, see Location in Response header', 403: 'forbidden'}, operation_description="Carve SchedulingUnitDraft in stone, and make an (uneditable) blueprint out of it.") @@ -594,6 +598,9 @@ class SchedulingUnitBlueprintViewSet(LOFARViewSet): # prefetch all reverse related references from other models on their related_name to avoid a ton of duplicate queries queryset = queryset.prefetch_related('task_blueprints') + # use select_related for forward related references + queryset = queryset.select_related('requirements_template', 'draft') + @swagger_auto_schema(responses={201: "This SchedulingUnitBlueprint, with references to its created TaskBlueprints and (scheduled) Subtasks.", 403: 'forbidden'}, operation_description="Create TaskBlueprint(s) for this scheduling unit, create subtasks, and schedule the ones that are not dependend on predecessors.") @@ -779,7 +786,11 @@ class TaskBlueprintViewSet(LOFARViewSet): # prefetch nested references in reverse models to avoid duplicate lookup queries queryset = queryset.prefetch_related('first_scheduling_relation__placement') \ - .prefetch_related('second_scheduling_relation__placement') + .prefetch_related('second_scheduling_relation__placement') \ + .prefetch_related('subtasks__specifications_template') + + # use select_related for forward related references + queryset = queryset.select_related('draft', 'specifications_template', 'specifications_template__type', 'scheduling_unit_blueprint') @swagger_auto_schema(responses={201: "This TaskBlueprint, with it is created subtasks", 403: 'forbidden'},