#8307: ImageFile use of width_field and height_field is slow with remote storage
backends
-------------------------------------+-------------------------------------
     Reporter:  sebastian.serrano@…  |                    Owner:  Jacob
         Type:                       |                   Status:  new
  Cleanup/optimization               |
    Component:  File                 |                  Version:  dev
  uploads/storage                    |
     Severity:  Normal               |               Resolution:
     Keywords:  imagefile height     |             Triage Stage:  Accepted
  width                              |
    Has patch:  1                    |      Needs documentation:  1
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Comment (by john-parton):

 I've got a fix that I think should pretty much always work.

 Like I alluded to earlier, it requires some deep knowledge of Django's
 internals. You have to know exactly when to side-step a descriptor and
 what the purpose of the descriptor is.

 Basically, the FileField.save() method will call the descriptors __set__
 method with the value being a string. That's required, because the storage
 backend might return a different string than you originally fed in. I
 believe the motivating reason for this was to avoid accidentally
 overwriting files. The other function of the descriptor is to calculate
 and store the width and height values if it's configured. However, the
 descriptor's __set__ method had to of been already called to even get to
 this point in the save flow. Because the __set__ method of the descriptor
 basically only serves this one function and the function has been
 satisfied earlier, I just side step the descriptor by manipulating the
 instances __dict__ directly.

 Here's the meat of the code: https://github.com/john-parton/django-image-
 field-extra-read/blob/bugfix/proposed-fix/test_app/fields.py

 Of course, I wouldn't want to make a change like this without some tests.
 As I said, I believe the primary purpose of the descriptor use there is
 update the string value of the file field, which I have made sure that
 it's updated to a non-conflicting value on subsequent saves.

 Here's a test case that I wrote which captures some of the spirit of what
 I'm trying to do: https://github.com/john-parton/django-image-field-extra-
 read/blob/bugfix/proposed-fix/test_app/tests.py

 I'm happy to take feedback, or I can work on building a proper patch.
-- 
Ticket URL: <https://code.djangoproject.com/ticket/8307#comment:17>
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 django-updates+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/0107018d3d78bb9c-aba5cf18-305b-481d-84f9-c8eeeb6f7345-000000%40eu-central-1.amazonses.com.

Reply via email to