Opened 6 years ago

Closed 2 years ago

#9631 closed Cleanup/optimization (fixed)

FieldFile assumes efficient Storage.size

Reported by: psagers 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 psagers 6 years ago.
Change in FieldFile._get_size

Download all attachments as: .zip

Change History (8)

Changed 6 years ago by psagers

Change in FieldFile._get_size

comment:1 Changed 6 years ago by jacob

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Design decision needed

comment:2 follow-up: Changed 6 years ago by redbaron

  • Version changed from 1.0 to 1.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 6 years ago by kmtracey

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 4 years ago by lukeplant

  • Severity set to Normal
  • Type set to Cleanup/optimization

comment:5 Changed 3 years ago by aaugustin

  • UI/UX unset

Change UI/UX from NULL to False.

comment:6 Changed 3 years ago by aaugustin

  • Easy pickings unset

Change Easy pickings from NULL to False.

comment:7 Changed 2 years ago by jacob

  • Resolution set to fixed
  • Status changed from new to closed

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