From 35afb10addefab934229b36b0b373f382dca3539 Mon Sep 17 00:00:00 2001 From: Elijah DeLee Date: Wed, 10 Aug 2022 16:38:59 -0400 Subject: [PATCH] fix use of distinct on query that UI When on the screen in the UI that loads the job events, the ui includes a filter to exclude job events where stdout = ''. Because this is a TextField and was not in the allow list, we were applying DISTINCT to the query. This made it very unperformant for large jobs, especially on the query that gets the count and cannot put a LIMIT on the query. Also correctly prefetch the related job_template data on the view to cut down the number of queries we make from around 50 to under 10. We need to analyze other similar views for other prefetch type optimizations we should make. --- awx/api/filters.py | 2 +- awx/api/views/__init__.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/awx/api/filters.py b/awx/api/filters.py index e296019e75..eaec6628ef 100644 --- a/awx/api/filters.py +++ b/awx/api/filters.py @@ -157,7 +157,7 @@ class FieldLookupBackend(BaseFilterBackend): # A list of fields that we know can be filtered on without the possiblity # of introducing duplicates - NO_DUPLICATES_ALLOW_LIST = (CharField, IntegerField, BooleanField) + NO_DUPLICATES_ALLOW_LIST = (CharField, IntegerField, BooleanField, TextField) def get_fields_from_lookup(self, model, lookup): diff --git a/awx/api/views/__init__.py b/awx/api/views/__init__.py index f67ab6622d..f6b7fbbabe 100644 --- a/awx/api/views/__init__.py +++ b/awx/api/views/__init__.py @@ -3839,7 +3839,7 @@ class JobJobEventsList(BaseJobEventsList): def get_queryset(self): job = self.get_parent_object() self.check_parent_access(job) - return job.get_event_queryset().select_related('host').order_by('start_line') + return job.get_event_queryset().prefetch_related('job__job_template', 'host').order_by('start_line') class JobJobEventsChildrenSummary(APIView):