Skip to content
Snippets Groups Projects
Commit 621c1f13 authored by catch's avatar catch
Browse files

Merge branch '1237636-entity-lazy-multiple' into '11.x'

Initial proof of concept for delayed multiple loading of entities.

See merge request !10738
parents a1026cc9 ba2d5a5f
No related branches found
No related tags found
No related merge requests found
Pipeline #470907 failed
......@@ -89,6 +89,11 @@ abstract class EntityStorageBase extends EntityHandlerBase implements EntityStor
*/
protected $memoryCacheTag;
/**
* Entity IDs awaiting loading.
*/
protected array $entityIdsToLoad = [];
/**
* Constructs an EntityStorageBase instance.
*
......@@ -285,6 +290,21 @@ public function loadMultiple(?array $ids = NULL) {
$ids = array_keys(array_diff_key($flipped_ids, $entities));
}
if ($ids) {
$this->entityIdsToLoad += $ids;
$fiber = \Fiber::getCurrent();
if ($fiber !== NULL) {
$fiber->suspend();
}
$entities += $this->getFromStaticCache($this->entityIdsToLoad);
// Replace the IDs to load with the full list of entity IDs to load
// collected from previous calls to this method up to this point.
if ($entities) {
$ids = array_keys(array_diff_key(array_flip($this->entityIdsToLoad), $entities));
}
$this->entityIdsToLoad = [];
}
// Try to gather any remaining entities from a 'preload' method. This method
// can invoke a hook to be used by modules that need, for example, to swap
// the default revision of an entity with a different one. Even though the
......
......@@ -145,7 +145,6 @@ public function prepareView(array $entities_items) {
$target_type = $this->getFieldSetting('target_type');
$target_entities = \Drupal::entityTypeManager()->getStorage($target_type)->loadMultiple($ids);
}
// For each item, pre-populate the loaded entity in $item->entity, and set
// the 'loaded' flag.
foreach ($entities_items as $items) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment