#35779: ORM to avoid deferring the reference_id of a prefetch
-------------------------------------+-------------------------------------
Reporter: Thiago Bellini | Owner:
Ribeiro | GunSliger00007
Type: Uncategorized | Status: assigned
Component: Database layer | Version: 4.2
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by GunSliger00007):
Consider optimizing your queries by prefetching only the fields you need.
In your case, you’re already using only() to limit the fields loaded by
the query, which helps reduce the amount of data loaded into memory.If the
related Email objects are large, consider using .values() or
.values_list() to reduce the amount of data furthe
User.objects.prefetch_related(
Prefetch("email_set", queryset=Email.objects.only("user_id", "email"))
)
--
Ticket URL: <https://code.djangoproject.com/ticket/35779#comment:2>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/01070192116c12ed-9f165a30-ae3b-4915-8c8b-048edaa518ff-000000%40eu-central-1.amazonses.com.