Problem/Motivation
\Drupal\jsonapi\JsonApiResource\ResourceIdentifier::toResourceIdentifiers iterates of a EntityReferenceFieldItemListInterface field list and individually loads each referenced entity. This can be improved by loading all referenced entities ahead of time.
Steps to reproduce
Visit a relationship endpoint for an entity.
Proposed resolution
Call referencesEntities before iterating over the field list's values
public static function toResourceIdentifiers(EntityReferenceFieldItemListInterface $items) {
// Load all referenced entities ahead of time.
$items->referencedEntities();
$relationships = [];
foreach ($items->filterEmptyItems() as $item) {
Remaining tasks
Before and after profiling?
User interface changes
None
API changes
None
Data model changes
None