#16937: Prefetch related objects
-------------------------------------+-------------------------------------
Reporter: lukeplant | Owner: nobody
Type: New feature | Status: closed
Component: Database layer | Version: 1.3
(models, ORM) | Resolution: fixed
Severity: Normal | Triage Stage: Ready for
Keywords: | checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by mkai):
Thanks for your great work! I'm still amazed by the quality standards of
the Django community. Also, the timing is very good - I'm currently
refactoring my project with the goal of minimizing database queries and
have already made good use of `prefetch_related`.
I've noticed that the code supports traversing over a `GenericForeignKey`
relation and prefetching its related objects. Would it be possible to also
support prefetching the objects that the generic foreign key points to?
I'm thinking of a model that has a generic foreign key to a `User` object,
for example. If 30 instances of this model are being traversed, and all 30
instances refer to the same `User` object, then the `User` object will be
fetched from the database 30 times. I've seen ways around this
(http://djangosnippets.org/snippets/1773/ for example), but, other than
`prefetch_related`, all of them evaluate the queryset immediately (and
none of them is in Django core).
Do you think prefetching the objects behind generic foreign keys (not
their relations) could/ should be added to `prefetch_related`? Or does it
rather belong into `django.contrib.contenttypes`, as `prefetch_generic`
maybe?
--
Ticket URL: <https://code.djangoproject.com/ticket/16937#comment:26>
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 post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en.