Problem/Motivation

I first reported in #3558370: Expand preloading in formatter

We prematurely load all ERR referenced entities when ::load() or ::loadeMultiple is called. In our case, we're loading several hundreds of entities with base fields in a JSON::API feed. What we'd rather have happen is delay loading all the ERR entities until later, at which point we'll load them all in a ::loadMultiple(). We've got things tuned so we have one ::loadMultiple() that loads up 500 entities at a time in (1) query. Because of this erring code, that results in 1+500 additional queries for each of the ERR fields. Whereas if this delayed the loading until later, we'd only have (2) queries.

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

heddn created an issue. See original summary.

heddn’s picture

Status: Active » Needs review
berdir’s picture

I think the API I added to ERRItem for the preloading can help here: \Drupal\entity_reference_revisions\Plugin\Field\FieldType\EntityReferenceRevisionsItem::isEntityLoaded(). Using that will benefit anyone, including those who implement this interface. Because we can safely assume that only a loaded/set entity object can have this flag set I think.

heddn’s picture

Updated MR to use that API.

rosk0’s picture

Thank you both this!

For me it also was responsible for the FiberError: Cannot switch fibers in current execution context in Fiber->start() (line 26 of core/lib/Drupal/Core/Field/Plugin/Field/FieldType/EntityReferenceItemBase.php).

Tested on PHP 8.3 with Drupal 11.3.3 and Entity Reference Revisions 8.x-1.14.

  • berdir committed 7ef44e68 on 8.x-1.x authored by heddn
    fix: #3572357 EntityReferenceRevisionsItem prematurely loads referenced...
berdir’s picture

Status: Reviewed & tested by the community » Fixed

Merged.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

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