Skip to content
Snippets Groups Projects

Draft: combined branch

All threads resolved!

Files

+ 35
1
@@ -89,6 +89,13 @@ abstract class EntityStorageBase extends EntityHandlerBase implements EntityStor
*/
protected $memoryCacheTag;
/**
* Entity IDs awaiting loading.
*
* @var list<int|string>
*/
protected array $entityIdsToLoad = [];
/**
* Constructs an EntityStorageBase instance.
*
@@ -285,6 +292,33 @@ public function loadMultiple(?array $ids = NULL) {
$ids = array_keys(array_diff_key($flipped_ids, $entities));
}
// @todo Find out why file entities cause time and space to collapse.
if ($ids && \Fiber::getCurrent() !== NULL && $this->entityType->isStaticallyCacheable() && $this->entityTypeId !== 'file') {
// Before suspending the fiber, add the IDs passed in to the full list
// of entities to load, so that another call can load everything at
// once.
$this->entityIdsToLoad = array_unique(array_merge($this->entityIdsToLoad, $ids));
\Fiber::suspend();
// Another call to this method may have reset the entityIdsToLoad
// property after loading entities. Combine it with the passed in IDs
// again in case this has happened.
$this->entityIdsToLoad = array_unique(array_merge($this->entityIdsToLoad, $ids));
$entities += $this->getFromStaticCache($this->entityIdsToLoad);
if ($entities) {
// Remove any entities found in the static cache from the IDs to load.
$ids = array_keys(array_diff_key(array_flip($this->entityIdsToLoad), $entities));
}
else {
// If nothing was found in the static cache, load every entity ID
// requested so far.
$ids = $this->entityIdsToLoad;
}
// Now that we've reached this point, unset the list of entity IDs to
// load so that further calls start with a blank slate (apart from the
// entity static cache itself).
$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
@@ -300,7 +334,7 @@ public function loadMultiple(?array $ids = NULL) {
// If any entities were pre-loaded, remove them from the IDs still to
// load.
$ids = array_keys(array_diff_key($flipped_ids, $entities));
$ids = array_keys(array_diff_key(array_flip($ids), $entities));
// Add pre-loaded entities to the cache.
$this->setStaticCache($preloaded_entities);
@@ -330,7+364,7 @@
// Remove any invalid IDs from the array and preserve the order passed in.
$flipped_ids = array_intersect_key($flipped_ids, $entities);
$entities = array_replace($flipped_ids, $entities);
}
return $entities;
}
Loading