I don't understand how metadata and cache work together.
If I query many entities and get metadata of each like :
$entities = elgg_get_entities(...); foreach($entities as $entity) {
$md1 = $entity->md1; $md2 = $entity->md2; $md3 = $entity->md3;}
There is the same count of queries in global $dbcalls if I remove this foreach loop or not !?
Could I reduce the number of queries like that ?
$entities = elgg_get_entities(...);
foreach($entities as $entity) {
$mds = elgg_get_metadata(array(
'guid' => $entity->getGUID(),
'metadata_names' => array('md1', 'md2', 'md3')
));
}
There is a way to populate many entities with many metadata with the less queries possible ?
info@elgg.org
Security issues should be reported to security@elgg.org!
©2014 the Elgg Foundation
Elgg is a registered trademark of Thematic Networks.
Cover image by RaĆ¼l Utrera is used under Creative Commons license.
Icons by Flaticon and FontAwesome.
- ihayredinov@ihayredinov
ihayredinov - 1 like
- ManUtopiK@ManUtopiK
ManUtopiK - 0 likes
- Steve Clay@steve_clay
Steve Clay - 0 likes
You must log in to post replies.All entity metadata is retrieved with a single DB call (metadata is preloaded, and not loaded on demand). The second option will generate more queries.
Thanks for your quick response.
Do you mean all metadatas of all entities are retrieved with a single DB call ?
Elgg maintains an in-memory (during the request) cache of metadata. Whenever entities are fetched, the cache is fully populated for those entities, with a single query.
But if you do 10 separate get_entity() calls, at worst that might produce 10 metadata queries. So batch up entities fetches if you can, and use the prefetch_* options where it makes sense.