On my homepage, i have a "mega menu" for taxons (~800 taxons)
In createTaxonsMenu function from Sylius\Bundle\WebBundle\Menu\FrontendMenuBuilder, there is a recursive call to createTaxonsMenuNode.
That make a lot of queries in my case, 1003 to be exact, because of that part of code
foreach ($taxon->getChildren() as $child) {
If we use childrenHierarchy from Gedmo TreeRepository instead of
$taxons = $this->channelContext->getChannel()->getTaxons();
i assume we can drastically decreased that number
WDYT ?
This is crazy... That's why WebBundle must go away! :) That being said, I will happily merge this optimization. Generally using KNPMenu for rendering categories is a bad idea and not happening in ShopBundle.
Agreed.
Ok will work on it.
When, or in which tag ShopBundle will be used ?
If you are goint to use all children you can probably "warmup" database and make it as one query before this loop.
I think i will use getChildren() of repository as it seems to fit better that use case.
Of course, i will only do one query, i will modify that line
$taxons = $this->channelContext->getChannel()->getTaxons();
What do you mean about "warmup" database ?
well i dont have time for exact example but executing query from repository like i use it on my other symfony project $warmupProduct = $em->getRepository('StraganCoreBundle:Product')
->createQueryBuilder('p')
->addSelect('i')
->leftJoin('p.info', 'i')
->addSelect('t')
->leftJoin('p.taxGroup', 't')
->where('p.id = :id')
->setParameter('id', $product->getId())
->getQuery()
->getResult();
i hope its clear and whats you are after.
Yes, i see, that was my idea :smile:
Even better, TreeRepository as already that query :tada:
I'm stuck on that one, there is no clean way to use it.
In fact, we can only extends Gedmo/Tree/Entity/Repository/NestedTreeRepository.php but TaxonRepository extends Sylius\Bundle\ResourceBundle\Doctrine\ORM\EntityRepository
Traits are not available on gedmo/doctrine-extensions 2.4.13, only on master.
So i have two choice :
Would you agree on second choice @pjedrzejewski with a "TODO remove when upgrade gedmo/doctrine-fixtures" comment on it or you prefer to wait ?
WebBundle was removed.