More aggressive entity caching
|Reported by:||ewinslow||Owned by:||ewinslow|
$entities = elgg_get_entities(array(...)); // complicated db call get_entity($entities->guid); //hits db again! get_entity($entities->guid); //hits db again!
The above situation is common and pointless. We already loaded the entity, we should just be able to hit a local cache (i.e. it should not require a shared memory cache like memcache).
Once we have this optimization in place for elgg_get_entities, we can (ab)use it as the basis for other optimizations. E.g. currently when you are displaying the river, it's 1 query to get all the relevant river entries, and then 1 more query per owner, and object, plus another for each set of comments, plus another for each comment's owner, etc.
Instead, in elgg_get_river, we can preload all the entities referenced from the results by looping over them, pulling out owner_guid and object_guid into an array, and then doing elgg_get_entities(array('guids' => $guids)); Now $item->getOwnerEntity() and $item->getObjectEntity() will just hit the cache.
Since this is invisible to the API, we can include it in a bugfix release, so I'm slating for 1.8.x.
Change History (6)
comment:1 Changed 12 months ago by ewinslow
- Owner set to ewinslow
- Status changed from new to assigned
comment:5 Changed 9 months ago by Evan Winslow
- Resolution set to fixed
- Status changed from assigned to closed