From 153740da9d3dd16a8c33b676b1f50d5496e831ff Mon Sep 17 00:00:00 2001 From: Jorrit Schaap <schaap@astron.nl> Date: Mon, 22 Jan 2024 12:55:36 +0100 Subject: [PATCH] TMSS-2886: little query optimization --- SAS/TMSS/backend/src/tmss/tmssapp/views.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/SAS/TMSS/backend/src/tmss/tmssapp/views.py b/SAS/TMSS/backend/src/tmss/tmssapp/views.py index 53b19aaf6cd..8291fe5a4ca 100644 --- a/SAS/TMSS/backend/src/tmss/tmssapp/views.py +++ b/SAS/TMSS/backend/src/tmss/tmssapp/views.py @@ -757,10 +757,12 @@ def failure_report(request): def public_schedule(request): '''return the current and future running and scheduled units in either html table or json depending on the request accept header''' # get all current and future running and scheduled units - scheduled_or_running_units = models.SchedulingUnitBlueprint.objects.filter(status__value__in=models.SchedulingUnitStatus.ACTIVE_STATUS_VALUES) \ + scheduled_or_running_units = models.SchedulingUnitBlueprint.objects.prefetch_related('task_blueprints__specifications_template__type') \ + .select_related(models.SchedulingUnitBlueprint.path_to_project, 'status', 'specifications_template', 'specifications_template') \ + .filter(status__value__in=models.SchedulingUnitStatus.ACTIVE_STATUS_VALUES) \ .filter(obsolete_since__isnull=True) \ .filter(on_sky_stop_time__gte=datetime.utcnow()) \ - .order_by('on_sky_start_time').all() + .order_by('on_sky_start_time').all()[:3] # return json if requested if 'json' in request.headers.get('Accept','').lower(): -- GitLab