From 5723bd8dd823ee855625e250df39393e26709d48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Bogda=C5=82?= Date: Wed, 20 Dec 2023 01:17:43 +0100 Subject: [PATCH] Fix: speed up admin panel for installs with a large number of documents (#5052) --- src/documents/admin.py | 33 +++++++++++++++++++++++++++++---- src/paperless_mail/admin.py | 4 ++++ 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/src/documents/admin.py b/src/documents/admin.py index d648d5829..5df235618 100644 --- a/src/documents/admin.py +++ b/src/documents/admin.py @@ -28,8 +28,9 @@ class CorrespondentAdmin(GuardedModelAdmin): class TagAdmin(GuardedModelAdmin): list_display = ("name", "color", "match", "matching_algorithm") - list_filter = ("color", "matching_algorithm") + list_filter = ("matching_algorithm",) list_editable = ("color", "match", "matching_algorithm") + search_fields = ("color", "name") class DocumentTypeAdmin(GuardedModelAdmin): @@ -107,6 +108,9 @@ class SavedViewAdmin(GuardedModelAdmin): inlines = [RuleInline] + def get_queryset(self, request): # pragma: no cover + return super().get_queryset(request).select_related("owner") + class StoragePathInline(admin.TabularInline): model = StoragePath @@ -120,8 +124,8 @@ class StoragePathAdmin(GuardedModelAdmin): class TaskAdmin(admin.ModelAdmin): list_display = ("task_id", "task_file_name", "task_name", "date_done", "status") - list_filter = ("status", "date_done", "task_file_name", "task_name") - search_fields = ("task_name", "task_id", "status") + list_filter = ("status", "date_done", "task_name") + search_fields = ("task_name", "task_id", "status", "task_file_name") readonly_fields = ( "task_id", "task_file_name", @@ -138,12 +142,25 @@ class NotesAdmin(GuardedModelAdmin): list_display = ("user", "created", "note", "document") list_filter = ("created", "user") list_display_links = ("created",) + raw_id_fields = ("document",) + search_fields = ("document__title",) + + def get_queryset(self, request): # pragma: no cover + return ( + super() + .get_queryset(request) + .select_related("user", "document__correspondent") + ) class ShareLinksAdmin(GuardedModelAdmin): list_display = ("created", "expiration", "document") list_filter = ("created", "expiration", "owner") list_display_links = ("created",) + raw_id_fields = ("document",) + + def get_queryset(self, request): # pragma: no cover + return super().get_queryset(request).select_related("document__correspondent") class CustomFieldsAdmin(GuardedModelAdmin): @@ -157,7 +174,15 @@ class CustomFieldInstancesAdmin(GuardedModelAdmin): fields = ("field", "document", "created", "value") readonly_fields = ("field", "document", "created", "value") list_display = ("field", "document", "value", "created") - list_filter = ("document", "created") + search_fields = ("document__title",) + list_filter = ("created", "field") + + def get_queryset(self, request): # pragma: no cover + return ( + super() + .get_queryset(request) + .select_related("field", "document__correspondent") + ) admin.site.register(Correspondent, CorrespondentAdmin) diff --git a/src/paperless_mail/admin.py b/src/paperless_mail/admin.py index a266b85ae..be9df4c44 100644 --- a/src/paperless_mail/admin.py +++ b/src/paperless_mail/admin.py @@ -119,6 +119,10 @@ class MailRuleAdmin(GuardedModelAdmin): ordering = ["order"] + raw_id_fields = ("assign_correspondent", "assign_document_type") + + filter_horizontal = ("assign_tags",) + class ProcessedMailAdmin(admin.ModelAdmin): class Meta: