Opened 18 years ago

Closed 17 years ago

#3436 closed (wontfix)

Don't fetch Field's choices on form/manipulator creation

Reported by: Ivan Sagalaev <Maniac@…> Owned by: nobody
Component: Core (Other) Version: dev
Severity: Keywords: performance
Cc: Maniac@…, gabor@… Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: yes
Easy pickings: no UI/UX: no

Description

Currently creation of a default manipulator for a model causes actual fetching of all content of every related parent models which tends to be slow. They are used to fill <select>s created for ForeignKeys and ManyToManyFields but this may be unnecessary if those <select>s never rendered. This can be easily fixed by turning a method that gets choices for <select>s (Field.get_choices()) into a generator that will hit database only when (and if) needed.

Patch follows.

Attachments (1)

3436.diff (1.4 KB ) - added by Ivan Sagalaev <Maniac@…> 18 years ago.
Patch

Download all attachments as: .zip

Change History (12)

by Ivan Sagalaev <Maniac@…>, 18 years ago

Attachment: 3436.diff added

Patch

comment:1 by Ivan Sagalaev <Maniac@…>, 18 years ago

Has patch: set

comment:2 by Gary Wilson <gary.wilson@…>, 18 years ago

Patch needs improvement: set
Triage Stage: UnreviewedAccepted

Marking this as accepted, but new feature will probably not get added to Manipulators. Does newforms exhibit the same problem? If so, it would be great if someone could submit a patch for newforms.

comment:3 by Ivan Sagalaev <Maniac@…>, 18 years ago

Gary, this code lives in db field, not old form fields, so it works for newforms too. Actually it was created after concerns in django-developers about newforms fetching related values like old forms.

comment:4 by Malcolm Tredinnick, 18 years ago

If we ever need it for verifying this problem, Joe Heck put a test case in #2638.

comment:5 by Malcolm Tredinnick, 17 years ago

Component: Database wrapperCore framework

comment:6 by anonymous, 17 years ago

Cc: gabor@… added

comment:7 by Ivan Sagalaev <Maniac@…>, 17 years ago

Keywords: performance added

comment:8 by Malcolm Tredinnick, 17 years ago

A small comment about this change (since I've looked at it, but don't have cycles to complete the work at the moment)...

I looked at this patch a couple of weeks ago. It wasn't immediately clear where the performance improvement appeared. It's definitely an improvement for some uses, but are we hitting those uses in newforms?

So we need a test to demonstrate how this is triggered, I think. It's a slight backwards incompatible change (since the returned type of get_choices changes). It wasn't apparent when I moved Joe Heck's example from #2638 over to newforms, for example.

comment:9 by Ivan Sagalaev <Maniac@…>, 17 years ago

To clarify... You want a regression test showing that it works properly or a test showing a performance gain? I'm not sure how to do the latter. And the former is show by any newforms test that renders a <select>.

comment:10 by Ivan Sagalaev <Maniac@…>, 17 years ago

Ok, I've tested it a bit. The problem really doesn't affect newforms since Field.formfield calls get_choices only if a field has explicit 'choices' attribute set. ForeignKeys don't have choices and are fetched by formfield's widget only at display time. Oldforms still have a problem though.

comment:11 by James Bennett, 17 years ago

Resolution: wontfix
Status: newclosed

Per comments above this is not a problem in newforms, and the old forms system is deprecated, so I'm marking this wontfix.

Note: See TracTickets for help on using tickets.
Back to Top