From 0d5a4cc74e37ef086d9f8fed550bdeb6012f3ce0 Mon Sep 17 00:00:00 2001 From: Dharshana Vanderbona Date: Wed, 18 Sep 2024 15:52:08 +0100 Subject: [PATCH] Load the related objects eagerly. Enable eager fetch for the review and application list page view. This will stop the system from generating N+1 sub queries on loading the associated objects. --- .../request/admin/model_admins.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/request_a_govuk_domain/request/admin/model_admins.py b/request_a_govuk_domain/request/admin/model_admins.py index a8999223..77f1ecbe 100644 --- a/request_a_govuk_domain/request/admin/model_admins.py +++ b/request_a_govuk_domain/request/admin/model_admins.py @@ -172,6 +172,15 @@ class ReviewAdmin(SimpleHistoryAdmin, FileDownloadMixin, admin.ModelAdmin): model = Review form = ReviewForm change_form_template = "admin/review_change_form.html" + list_select_related = [ + "application", + "application__owner", + "application__last_updated_by", + "application__registrar_person", + "application__registrant_person", + "application__registrant_org", + "application__registrar_org", + ] list_display = ( "get_reference", @@ -516,6 +525,14 @@ class ApplicationAdmin( django.db.models.fields.files.FileField: {"widget": CustomAdminFileWidget}, } actions = ["export", "archive"] + list_select_related = [ + "owner", + "last_updated_by", + "registrar_person", + "registrant_person", + "registrant_org", + "registrar_org", + ] def download_file_view(self, request, object_id, field_name): application = self.model.objects.get(id=object_id)