Problem/Motivation
I first reported in #3558370: Expand preloading in formatter
We prematurely load all ERR referenced entities when
::load()or::loadeMultipleis 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
Issue fork entity_reference_revisions-3572357
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
Comment #3
heddnComment #4
berdirI 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.
Comment #5
heddnUpdated MR to use that API.
Comment #6
rosk0Thank 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.
Comment #8
berdirMerged.