#26690: Add the option in the prefetch_related to have the prefetched results
returned as a list or as a queryset
-------------------------------------+-------------------------------------
     Reporter:  Ursidours            |                    Owner:  nobody
         Type:  New feature          |                   Status:  new
    Component:  Database layer       |                  Version:  master
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:
     Keywords:  Prefetch             |             Triage Stage:
  prefetch_related queryset          |  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------

Comment (by charettes):

 Personally I'm -0 on adding such a feature for the following reasons:

 > In many cases, there is no need to chain further queries to the default
 prefetch_related. By explicitly asking for a list it would then become
 possible to benefit from the speed improvement.

 The default `prefetch_related()` results are stored in a `QuerySet()` in
 order to make sure the returned instances' prefetched relations still
 behave the same as if they were not prefetched. Storing lists in there
 would make such instances/querysets unusable by many components of Django
 such as forms and model level validation where it would fail in non-
 obvious ways.

 Using `Prefetch('relation', to_attr='relation_as_list')` already serves
 this purpose and don't think introducing another way to do it such as
 `Prefetch('relation', as_list=True)` is worth it. If we'd really want to
 speed up default prefetches I think we should investigate assigning
 objects that quack like `QuerySet` (e.g. `PrefetchedQuerySet`) but only
 lazily build their underlying query when required as this is the part that
 slow down performance here.

 > Conversely, some developers may be happy to take the performance hit in
 order to further refine a Prefetch with to_attr.

 I've never personally required to refine a prefetched result, that sounds
 like an anti-pattern to me.

--
Ticket URL: <https://code.djangoproject.com/ticket/26690#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 post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/067.8b97d78ea98e823fa8882bdbd33c3d12%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to