Quantcast
Viewing all articles
Browse latest Browse all 294806

Cached entities are loaded again, if $condition is given.

DrupalDefaultEntityController::load(), on the first attempt to load entities, will
- load the raw entities from the database.
- attach fields and possibly more with ::attachLoad() to the entity objects.

On subsequent calls for the same ids, it will get these entities from the cache in $this->entityCache.
This way, it avoids redundant and repeated database queries and calls to ::attachLoad().

However, if DrupalDefaultEntityController::load() is called with a non-empty $condition array, and $ids === FALSE, then repeated calls to load entities by the same conditions will cause each time cause a query, and call ::attachLoad() for entities that are already in the cache.
The entities built this way are later discarded via $entities += $queried_entities.

Even in a case where both $ids and $conditions are provided, if only one id is missing, then ::attachLoad() will be called for all the entities, even those already in cache.

This can be avoided.

I don't know how common it is to repeatedly load entities by the same conditions.
But in case someone does, fixing this will radically reduce the time of this operation.


Viewing all articles
Browse latest Browse all 294806

Trending Articles



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