How to optimize the loading of your data
When querying your data using the API, you will only retrieve the Data entities without their associated Values, this is actually a good thing and you should'nt try to join and select the values collection inside your queries because it won't play well with any Pager in terms of performances.
The best way to optimize the loading of data in your app is to use the OptimizedDataLoader
:
<?php
/**
* @var \Sidus\EAVModelBundle\Doctrine\DataLoaderInterface $dataLoader
* @var \Sidus\EAVModelBundle\Entity\DataInterface $book
* @var \Sidus\EAVModelBundle\Entity\DataInterface[] $books
*/
$dataLoader->loadSingle($book);
$dataLoader->load($books);
This will ensure that all the required data are loaded in the minimum number of queries. By default it will load the current values of the entities and all the related embed entities.
If you need to load additional relations you can use the autoload
option for your relational attributes:
sidus_eav_model:
families:
Post:
attributeAsLabel: title
attributes:
# (...)
author:
type: data_selector
options:
autoload: true
allowed_families:
- Author
The second parameter of both loading method can be used to tweak the depth at which data will be fetched, you can increase the default value to allow the loader to fetch additional relations in your data tree.
<?php
/**
* @var \Sidus\EAVModelBundle\Doctrine\DataLoaderInterface $dataLoader
* @var \Sidus\EAVModelBundle\Entity\DataInterface $book
* @var \Sidus\EAVModelBundle\Entity\DataInterface[] $books
*/
$dataLoader->loadSingle($book, 3);
$dataLoader->load($books, 2);