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

Better Optimization of AttachmentInline #414

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
16 changes: 9 additions & 7 deletions post_office/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from django.core.exceptions import ValidationError
from django.core.mail.message import SafeMIMEText
from django.db import models
from django.db.models.functions import Cast
from django.forms import BaseInlineFormSet
from django.forms.widgets import TextInput
from django.http.response import (HttpResponse, HttpResponseNotFound,
Expand Down Expand Up @@ -48,13 +49,14 @@ def get_queryset(self, request):
if self.parent_obj:
queryset = queryset.filter(email=self.parent_obj)

inlined_attachments = [
a.id
for a in queryset
if isinstance(a.attachment.headers, dict)
and a.attachment.headers.get("Content-Disposition", "").startswith("inline")
]
return queryset.exclude(id__in=inlined_attachments)
# explicit cast is needed because JSON could be stored in TEXT type due incomplete migration introduced in
# https://github.com/ui/django-post_office/pull/438
return queryset.annotate(
_headers=Cast("attachment__headers", output_field=models.JSONField()),
).exclude(**{
"_headers__Content-Disposition__isnull": False,
"_headers__Content-Disposition__startswith": "inline"
})


class LogInline(admin.TabularInline):
Expand Down
Loading