file_get_file_references() is rather bogus

Created on 7 October 2012, about 12 years ago
Updated 18 April 2024, 7 months ago
  1. drupal_static misses the & sign, no static caching.
  2. If a field_type is given which holds a file id in a column not called fid, the EntityFieldQuery bombs. Entityreference might be an example.
  3. Even if we fix that, we run as many queries as many fields that field type has.
  4. If a field type type is not given, then we run one EFQ for every. single. field. in the site. With a hardwired fid column, mind you, so the query bombing will very quickly fatal.
  5. If you call this function multiple times with different fids, you always get the same results.
  6. If you call this function multiple times with different values for $age, you always get the same results.
  7. You can't leave $field AND $field_type empty, see point 4.
  8. The @return value is absolutely hilarious. The best docs is in wiredocs.module.

Solutions:

  1. Add a & sign.
  2. Figure out the column name from the field foreign keys. Entityreference does maintain this and so do the core fields.
  3. Use file_list_usage to run one query.
  4. This is already fixed in the previous two points.
  5. Cache by fid as well.
  6. Cache by age as well.
  7. This is already fixed as in points 4.
  8. Write proper @return doxygen.

Some of the code already exists in file_file_download which, in itself benefits from this patch: instead of loading entities one by one we load them multiple by the entity type. Also, other consumers of this function will benefit from not getting pseudo-entities but real ones.

🐛 Bug report
Status

Needs review

Version

7.0 ⚰️

Component
File system 

Last updated about 2 hours ago

Created by

🇨🇦Canada chx

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024