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

Poor performance in EmailAdmin view. #415

Open
barqshasbite opened this issue Sep 19, 2022 · 1 comment
Open

Poor performance in EmailAdmin view. #415

barqshasbite opened this issue Sep 19, 2022 · 1 comment

Comments

@barqshasbite
Copy link

There is a performance issue when viewing an Email in the EmailAdmin when there are a lot Emails and Attachments in the database. This is caused by customizing the get_queryset method of AttachmentInline to try to filter out inline attachments by their header values.

In the post_office.admin.AttachmentInline.get_queryset method, Django has not yet applied the Email FK filter to the queryset. That happens later when the inline formset is being created.

That means that the query being run in the get_queryset method actually fetches and iterates over every single Email Attachment object in the database, regardless of the Email it is for. In the loop, it also references the attachment property, but without a select_related on the query, it will have to fetch each attachment separately for every iteration.

If you have a lot of Emails and Attachments in the database, this causes performance issues.

barqshasbite added a commit to barqshasbite/django-post_office that referenced this issue Sep 19, 2022
Add a `filter` and `select_related` to the queryset to limit the
records being fetched by the custom `get_queryset` logic.

Fixes ui#415
@patroqueeet
Copy link
Contributor

I'd like to add for many users in db, the AttachmentAdmin is very slow to load.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants