Opened 8 years ago

Closed 4 years ago

#9631 closed Cleanup/optimization (fixed)

FieldFile assumes efficient Storage.size

Reported by: Peter Sagerson Owned by: nobody
Component: File uploads/storage Version: 1.1-beta
Severity: Normal Keywords: file upload compression
Cc: Triage Stage: Design decision needed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

FieldFile's _get_size, like many of its methods, passes the operation on to its Storage object. However, in this case, assuming that a storage mechanism can easily discover the size of a file by name is rather rash. If the file is compressed, for instance, it may be necessary to decompress the entire file to determine the size. Remote storage could suffer from similar issues.

Fortunately, FieldFile has a File object provided by the storage. The Storage derivative is responsible for returning a valid File object, which means it must be able to correctly report its size. By asking the File object for its size directly, we provide opportunities for caching so that a size request followed by a read operation need not trigger two independent retrievals of the data.

Attachments (1)

file_size.diff (461 bytes) - added by Peter Sagerson 8 years ago.
Change in FieldFile._get_size

Download all attachments as: .zip

Change History (8)

Changed 8 years ago by Peter Sagerson

Attachment: file_size.diff added

Change in FieldFile._get_size

comment:1 Changed 8 years ago by Jacob

Triage Stage: UnreviewedDesign decision needed

comment:2 Changed 8 years ago by Maxim Ivanov

Version: 1.01.1-beta-1

I've run into problem related to this bug. If we try to access file size in save() method of model, we are unable to get size, at least in case of InMemoryUploadedFile, because default storage unable to find file on FS.

comment:3 in reply to:  2 Changed 8 years ago by Karen Tracey

Replying to redbaron:

I've run into problem related to this bug. If we try to access file size in save() method of model, we are unable to get size, at least in case of InMemoryUploadedFile, because default storage unable to find file on FS.

This is actually the problem identified in #10300.

comment:4 Changed 6 years ago by Luke Plant

Severity: Normal
Type: Cleanup/optimization

comment:5 Changed 5 years ago by Aymeric Augustin

UI/UX: unset

Change UI/UX from NULL to False.

comment:6 Changed 5 years ago by Aymeric Augustin

Easy pickings: unset

Change Easy pickings from NULL to False.

comment:7 Changed 4 years ago by Jacob

Resolution: fixed
Status: newclosed

I think this was fixed as part of #10300. If that's not true, please reopen.

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