If width_field and height_field are not set, removing the post_init signal
should have no effect since the signal handler will return right away.
Removing this signal handler gave us a 30-40% speedup on initializing
models where ImageField was used.
--
Ticket URL: <https://code.djangoproject.com/ticket/34517>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* version: 4.1 => 4.2
--
Ticket URL: <https://code.djangoproject.com/ticket/34517#comment:1>
* stage: Unreviewed => Accepted
Comment:
Nice catch, thanks.
[https://github.com/django/django/pull/16801 PR]
--
Ticket URL: <https://code.djangoproject.com/ticket/34517#comment:2>
* owner: nobody => orhanhenrik
* status: new => assigned
--
Ticket URL: <https://code.djangoproject.com/ticket/34517#comment:3>
* needs_tests: 0 => 1
--
Ticket URL: <https://code.djangoproject.com/ticket/34517#comment:4>
* needs_tests: 1 => 0
* stage: Accepted => Ready for checkin
--
Ticket URL: <https://code.djangoproject.com/ticket/34517#comment:5>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"ea53e7c09f1b8864c20c65976bbeaeab77abdaec" ea53e7c]:
{{{
#!CommitTicketReference repository=""
revision="ea53e7c09f1b8864c20c65976bbeaeab77abdaec"
Fixed #34517 -- Avoided connection post_init signal to ImageField without
width/height fields.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/34517#comment:6>
Comment (by Mariusz Felisiak <felisiak.mariusz@…>):
In [changeset:"bcacc6321ae819965f478bfee2072a796801f298" bcacc63]:
{{{
#!CommitTicketReference repository=""
revision="bcacc6321ae819965f478bfee2072a796801f298"
Refs #34517 -- Restored skipping ImageFileField.update_dimension_fields
without width/height fields.
This avoids reading the image size when the dimensions fields
(image_width, image_height) do not exist, as that operation may be
expensive.
Partially reverts ea53e7c09f1b8864c20c65976bbeaeab77abdaec, that dropped
the check for the dimension fields in update_dimension_fields(), because
the post_init signal was no longer registered without dimension fields.
However, another code path to that function exists: when the
ImageFileField is save()d, the name from the storage is setattr()ed on
the field, and ImageFileDescriptor calls update_dimension_fields()
because the image size might have changed. Keep bailing out early when
dimensions are unused.
Besides, computing the image dimensions causes to close() the file,
resulting in a backward-incompatible change. The test protects against
that change.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/34517#comment:7>