[PATCH] admin: Configure 'list_select_related', 'get_queryset'

Stephen Finucane stephen at that.guru
Thu Sep 13 07:57:39 AEST 2018


This has a significant improvement for the patch and series views.

  /patchwork/patch
    FROM: ~114 queries
    TO: ~14 queries

  /patchwork/series
    FROM: ~210 queries
    TO: ~10 queries

Signed-off-by: Stephen Finucane <stephen at that.guru>
---
 patchwork/admin.py | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/patchwork/admin.py b/patchwork/admin.py
index 133872ac..1a2c0370 100644
--- a/patchwork/admin.py
+++ b/patchwork/admin.py
@@ -105,6 +105,7 @@ class PatchAdmin(admin.ModelAdmin):
     list_display = ('name', 'submitter', 'project', 'state', 'date',
                     'archived', 'is_pull_request')
     list_filter = ('project', 'state', 'archived')
+    list_select_related = ('submitter', 'project', 'state')
     search_fields = ('name', 'submitter__name', 'submitter__email')
     date_hierarchy = 'date'
 
@@ -145,6 +146,10 @@ class SeriesAdmin(admin.ModelAdmin):
         return series.received_all
     received_all.boolean = True
 
+    def get_queryset(self, request):
+        qs = super(SeriesAdmin, self).get_queryset(request)
+        return qs.prefetch_related('patches',)
+
 
 admin.site.register(Series, SeriesAdmin)
 
-- 
2.17.1



More information about the Patchwork mailing list