#32244: ORM inefficiency: ModelFormSet executes a single-object SELECT query per
formset instance when saving/validating
-------------------------------------+-------------------------------------
     Reporter:  Lushen Wu            |                    Owner:  nobody
         Type:                       |                   Status:  closed
  Cleanup/optimization               |
    Component:  Database layer       |                  Version:  3.1
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:  wontfix
     Keywords:  formsets             |             Triage Stage:
                                     |  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Changes (by Carlton Gibson):

 * status:  new => closed
 * resolution:   => wontfix


Comment:

 Hi. Thanks for the report.

 It looks like you'e dug into the various aspects.

 This seems to make the most sense to me:

 > The easiest solution seems to me to pass BaseModelFormSet._object_dict
 in some way to each ModelForm that's created, and then allow the
 ModelChoiceField to check this _object_dict before making another SELECT
 query.

 You'd pass a reference via the form kwargs, and then need a custom form
 and `ModelChoiceField` subclass to make use of it in `to_python()`.

 I have to say this is probably a `wontfix`. It's not likely that this is a
 performance bottleneck for most projects. Even several hundred lookups are
 not going to noticeably affect the form submission in normal cases.
 Projects needing to process data in a performant tight-loop will want to
 make adjustments as discusses here, but the complication there probably
 isn't worth it for the general case.

 If you experiment in your own project and come up with a clean and simple
 solution, it may be worth reviewing then, either here or on the
 DevelopersMailingList.

 I hope that makes sense.
 Thanks.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/32244#comment:7>
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/066.b1634d265880dbdfc870f8cc30543100%40djangoproject.com.

Reply via email to