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.
Updated: Comment #N
Problem/Motivation
\Drupal\taxonomy\Entity\Vocabulary::postSave() calls entity_load_multiple('field_entity'). Lets not load all of them all the time.
Proposed resolution
Maybe it is better to use FieldInfo::getFieldMap(), search through the cached data, then just load the ones we want - with a type of 'taxonomy_term_reference'.
Remaining tasks
Is this any more efficient? Likely, yes!
User interface changes
None
API changes
None
Comment | File | Size | Author |
---|---|---|---|
#10 | 2180039-10.patch | 2.11 KB | damiankloip |
Comments
Comment #1
chx CreditAttribution: chx commentedYou should never load all the fields, that's absolutely insane, there easily can be a thousand of them or more and the memory needed to load all would be sky high.
Comment #3
damiankloip CreditAttribution: damiankloip commentedComment #4
damiankloip CreditAttribution: damiankloip commentedSo getFieldMap uses the field name, but we need the field id to be able to load them all. The good news is that the test coverage caught this.
Comment #5
chx CreditAttribution: chx commentedHrm.
Comment #6
BerdirRight. The code is actually correct, just $module needs to be renamed to $entity_type, because that's what it is.
@chx: Note that field.module itself obviously has to load all field entities internally, to build this map. But agreed that user code should never do that.
Comment #7
BerdirNote: The propsed solution has the wrong field type (entity_term_reference, there is no such thing), but the implementation is correct :)
Comment #8
BerdirRenamed $module to $entity_type.
Comment #9
damiankloip CreditAttribution: damiankloip commentedYeah sorry, just kind of wrote out the code without really thinking, thanks berdir!
Comment #10
damiankloip CreditAttribution: damiankloip commentedRerolled, 'field_config'.
Comment #11
BerdirThis looks good, thanks!
Comment #12
alexpottCommitted cc618ea and pushed to 8.x. Thanks!