Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
file_file_download()
function loads all reference entities in a loop one by one. I think this can be optimized, loading all entities at once outside of the foreach
loop. As follows:
Before:
<?php
function file_file_download($uri, $field_type = 'file') {
// ...
foreach ($field_references as $entity_type => $type_references) {
foreach ($type_references as $id => $reference) {
$entity = entity_load($entity_type, array($id));
$entity = reset($entity);
// ...
}
}
// ...
}
After:
<?php
function file_file_download($uri, $field_type = 'file') {
// ...
foreach ($field_references as $entity_type => $type_references) {
$entities = entitiy_load($entity_type, array_keys($type_references));
foreach ($entities as $entity) {
// ...
}
}
// ...
}
Patch follows.
Comment | File | Size | Author |
---|---|---|---|
#2 | optimize-file-file-download-function-2856913-1.patch | 838 bytes | Elin Yordanov |
Comments
Comment #2
Elin Yordanov CreditAttribution: Elin Yordanov as a volunteer commentedAnd the patch. Please review.