Quantcast
Channel: Issues for Drupal core
Viewing all articles
Browse latest Browse all 299124

ResourceIdentifier::toResourceIdentifiers should preload all referenced entities for performance

$
0
0

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

Release notes snippet


Viewing all articles
Browse latest Browse all 299124

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>