#35810: Provide `Select` class for `select_related` (like `Prefetch` exists for
`prefetch_related`)
-------------------------------------+-------------------------------------
     Reporter:  Bart van Andel       |                    Owner:  (none)
         Type:  New feature          |                   Status:  new
    Component:  Database layer       |                  Version:  5.1
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:
     Keywords:  query optimization   |             Triage Stage:
                                     |  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Comment (by Bart van Andel):

 Note: I tried to optimize our use case like this (pseudo code):

 {{{
 if self.message_set.is_loaded:
     return max(self.message_set.all(), key=lambda item: item.created_at,
 default=None)
     # or, more clearly, but also not possible:
     return self.message_set.latest("created_at", trust_cached_data=True)
 else:
     return self.message_set.latest("created_at")

 # or, even more clearly, just get the value directly, using preloaded data
 if it exists:
 return self.message_set.latest("created_at", trust_cached_data=True)
 }}}

 There is no `is_loaded` or `trust_cached_data` (or equivalents) however,
 so this obviously won't work. Also, obviously this should be used with
 extreme care, but then again, when optimizing you sometimes need to be
 careful and creative anyway.
-- 
Ticket URL: <https://code.djangoproject.com/ticket/35810#comment:1>
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/01070192535d9710-0d02fcbd-67e2-41d1-b9b9-9f924d4e57ad-000000%40eu-central-1.amazonses.com.

Reply via email to