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

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

chx’s picture

You 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.

Status: Needs review » Needs work

The last submitted patch, d8.vocab-postSave.patch, failed testing.

damiankloip’s picture

Issue summary: View changes
damiankloip’s picture

Status: Needs work » Needs review
FileSize
2.1 KB
1.16 KB

So 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.

chx’s picture

   $field_ids[] = $module . '.' . $field;
  public function id() {
    return $this->entity_type . '.' . $this->name;
  }

Hrm.

Berdir’s picture

Status: Needs review » Needs work

Right. 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.

Berdir’s picture

Note: The propsed solution has the wrong field type (entity_term_reference, there is no such thing), but the implementation is correct :)

Berdir’s picture

Issue summary: View changes
Status: Needs work » Needs review
FileSize
2.11 KB
878 bytes

Renamed $module to $entity_type.

damiankloip’s picture

Yeah sorry, just kind of wrote out the code without really thinking, thanks berdir!

damiankloip’s picture

FileSize
2.11 KB

Rerolled, 'field_config'.

Berdir’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: +Performance

This looks good, thanks!

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed cc618ea and pushed to 8.x. Thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.