Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix performance of EmailAdmin view. #416

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion post_office/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,19 @@ def get_queryset(self, request):
are displayed anyway.
"""
queryset = super().get_queryset(request)

# The queryset does not have the Email FK filter applied at this point.
# That happens later when the inline formset is created as part of the
# admin view. Here we explicitly add the Email filter to avoid selecting
# every row in the table during this special filtering step.
email = request.resolver_match.kwargs.get("object_id", None)
if email is None:
return queryset
email_filter = queryset.filter(email=email).select_related("attachment")

inlined_attachments = [
a.id
for a in queryset
for a in email_filter
if isinstance(a.attachment.headers, dict)
and a.attachment.headers.get("Content-Disposition", "").startswith("inline")
]
Expand Down