Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Virtual Category] Optimize virtual category rule computation #3326

Merged
merged 1 commit into from
Jul 23, 2024

Conversation

PierreGauthier
Copy link
Contributor

Don't calculate virtual category root if parent category of the root category has been computed.

@PierreGauthier PierreGauthier changed the base branch from 2.11.x to 2.10.x July 16, 2024 14:55
Don't calculate virtual category root if parent category of the root category has been computed.
@PierreGauthier PierreGauthier force-pushed the fix-virtualCategoQueryComputing branch from a82c0c5 to 14c08fc Compare July 16, 2024 14:59
@romainruaud romainruaud merged commit f56d7cd into 2.10.x Jul 23, 2024
9 checks passed
@rbayet rbayet deleted the fix-virtualCategoQueryComputing branch August 29, 2024 13:02
@Nuranto
Copy link
Contributor

Nuranto commented Oct 7, 2024

Hello @PierreGauthier,

I recently switched from my fix to this problem, to yours which is more elegant (and has been merged)

However, your solution is actually not working for all cases. You do avoid useless calls to getVirtualCategoryQuery, but there is still calls to getCategorySearchQuery that are not coming from getVirtualCategoryQuery. Here's an example (admin/catalog/category page / preview) :

#0 /var/www/html/vendor/smile/elasticsuite/src/module-elasticsuite-virtual-category/Model/Rule.php(516): Smile\ElasticsuiteVirtualCategory\Model\Rule->getCategorySearchQuery(Object(Magento\Catalog\Model\Category\Interceptor), Array)
#1 /var/www/html/vendor/smile/elasticsuite/src/module-elasticsuite-virtual-category/Model/Rule.php(341): Smile\ElasticsuiteVirtualCategory\Model\Rule->addChildrenQueries(Object(Smile\ElasticsuiteCore\Search\Request\Query\Nested), Object(Magento\Catalog\Model\Category\Interceptor), Array)
#2 /var/www/html/vendor/smile/elasticsuite/src/module-elasticsuite-virtual-category/Model/Rule.php(227): Smile\ElasticsuiteVirtualCategory\Model\Rule->buildCategorySearchQuery(Object(Magento\Catalog\Model\Category\Interceptor), Array)
#3 /var/www/html/vendor/smile/elasticsuite/src/module-elasticsuite-virtual-category/Model/Preview.php(171): Smile\ElasticsuiteVirtualCategory\Model\Rule->getCategorySearchQuery(Object(Magento\Catalog\Model\Category\Interceptor))
#4 /var/www/html/vendor/smile/elasticsuite/src/module-elasticsuite-virtual-category/Model/Preview.php(115): Smile\ElasticsuiteVirtualCategory\Model\Preview->getQueryFilter()
#5 /var/www/html/vendor/smile/elasticsuite/src/module-elasticsuite-catalog/Model/ProductSorter/AbstractPreview.php(158): Smile\ElasticsuiteVirtualCategory\Model\Preview->prepareProductCollection(Object(Smile\ElasticsuiteCatalog\Model\ResourceModel\Product\Fulltext\Collection\Interceptor))
#6 /var/www/html/vendor/smile/elasticsuite/src/module-elasticsuite-catalog/Model/ProductSorter/AbstractPreview.php(199): Smile\ElasticsuiteCatalog\Model\ProductSorter\AbstractPreview->getProductCollection()
#7 /var/www/html/vendor/smile/elasticsuite/src/module-elasticsuite-catalog/Model/ProductSorter/AbstractPreview.php(101): Smile\ElasticsuiteCatalog\Model\ProductSorter\AbstractPreview->getUnsortedProductData()
#8 /var/www/html/vendor/smile/elasticsuite/src/module-elasticsuite-virtual-category/Controller/Adminhtml/Category/Virtual/Preview.php(70): Smile\ElasticsuiteCatalog\Model\ProductSorter\AbstractPreview->getData()

As you can see, we do not pass through getVirtualCategoryQuery here, and so we're building the full query like before your PR (leading in some cases to too_many_nested_clauses exception).

Same thing happens in front :

#0 [internal function]: Smile\ElasticsuiteVirtualCategory\Model\Rule->getCategorySearchQuery(Object(Magento\Catalog\Model\Category\Interceptor))
#1 /var/www/html/vendor/smile/elasticsuite/src/module-elasticsuite-virtual-category/Helper/Rule.php(110): call_user_func_array(Array, Array)
#2 /var/www/html/vendor/smile/elasticsuite/src/module-elasticsuite-virtual-category/Model/Category/Filter/Provider.php(87): Smile\ElasticsuiteVirtualCategory\Helper\Rule->loadUsingCache(Object(Magento\Catalog\Model\Category\Interceptor), 'getCategorySear...')
#3 /var/www/html/vendor/smile/elasticsuite/src/module-elasticsuite-virtual-category/Model/Category/Filter/Provider.php(70): Smile\ElasticsuiteVirtualCategory\Model\Category\Filter\Provider->getCategorySearchQuery(Object(Magento\Catalog\Model\Category\Interceptor))
#4 /var/www/html/vendor/smile/elasticsuite/src/module-elasticsuite-catalog/Model/Product/Search/Request/Container/Filter/CurrentCategory.php(70): Smile\ElasticsuiteVirtualCategory\Model\Category\Filter\Provider->getQueryFilter(Object(Magento\Catalog\Model\Category\Interceptor))
#5 /var/www/html/vendor/smile/elasticsuite/src/module-elasticsuite-core/Search/Request/ContainerConfiguration.php(139): Smile\ElasticsuiteCatalog\Model\Product\Search\Request\Container\Filter\CurrentCategory->getFilterQuery()
#6 /var/www/html/vendor/smile/elasticsuite/src/module-elasticsuite-core/Search/Request/Builder.php(207): Smile\ElasticsuiteCore\Search\Request\ContainerConfiguration->getFilters()
#7 /var/www/html/vendor/smile/elasticsuite/src/module-elasticsuite-core/Search/Request/Builder.php(149): Smile\ElasticsuiteCore\Search\Request\Builder->getContainerFilters(Object(Smile\ElasticsuiteCore\Search\Request\ContainerConfiguration))
#8 /var/www/html/vendor/magento/framework/Interception/Interceptor.php(58): Smile\ElasticsuiteCore\Search\Request\Builder->create(7, 'catalog_view_co...', 0, 0, NULL, Array, Array, Array, Array)
#9 /var/www/html/vendor/magento/framework/Interception/Interceptor.php(138): Smile\ElasticsuiteCore\Search\Request\Builder\Interceptor->___callParent('create', Array)
#10 /var/www/html/vendor/magento/framework/Interception/Interceptor.php(153): Smile\ElasticsuiteCore\Search\Request\Builder\Interceptor->Magento\Framework\Interception\{closure}(7, 'catalog_view_co...', 0, 0, NULL, Array, Array, Array, Array, true)
#11 /var/www/html/generated/code/Smile/ElasticsuiteCore/Search/Request/Builder/Interceptor.php(23): Smile\ElasticsuiteCore\Search\Request\Builder\Interceptor->___callPlugins('create', Array, Array)
#12 /var/www/html/vendor/smile/elasticsuite/src/module-elasticsuite-catalog/Model/ResourceModel/Product/Fulltext/Collection.php(631): Smile\ElasticsuiteCore\Search\Request\Builder\Interceptor->create(7, 'catalog_view_co...', 0, 0, NULL, Array, Array, Array, Array, true)
#13 /var/www/html/vendor/smile/elasticsuite/src/module-elasticsuite-catalog/Model/ResourceModel/Product/Fulltext/Collection.php(195): Smile\ElasticsuiteCatalog\Model\ResourceModel\Product\Fulltext\Collection->loadProductCounts()
#14 /var/www/html/vendor/smile/elasticsuite/src/module-elasticsuite-catalog/Model/ResourceModel/Product/Fulltext/Collection.php(489): Smile\ElasticsuiteCatalog\Model\ResourceModel\Product\Fulltext\Collection->getSize()
#15 /var/www/html/vendor/smile/elasticsuite/src/module-elasticsuite-catalog/Model/ResourceModel/Product/Fulltext/Collection.php(676): Smile\ElasticsuiteCatalog\Model\ResourceModel\Product\Fulltext\Collection->getPageSize()
#16 /var/www/html/vendor/smile/elasticsuite/src/module-elasticsuite-catalog/Model/ResourceModel/Product/Fulltext/Collection.php(519): Smile\ElasticsuiteCatalog\Model\ResourceModel\Product\Fulltext\Collection->prepareRequest()
#17 /var/www/html/vendor/magento/framework/Data/Collection/AbstractDb.php(542): Smile\ElasticsuiteCatalog\Model\ResourceModel\Product\Fulltext\Collection->_renderFiltersBefore()
#18 /var/www/html/vendor/smile/elasticsuite/src/module-elasticsuite-catalog/Model/ResourceModel/Product/Fulltext/Collection.php(574): Magento\Framework\Data\Collection\AbstractDb->_renderFilters()
#19 /var/www/html/vendor/smile/elasticsuite/src/module-elasticsuite-catalog/Model/ResourceModel/Product/Fulltext/Collection.php(382): Smile\ElasticsuiteCatalog\Model\ResourceModel\Product\Fulltext\Collection->_renderFilters()
#20 /var/www/html/vendor/smile/elasticsuite/src/module-elasticsuite-catalog/Model/Layer/Filter/Attribute.php(139): Smile\ElasticsuiteCatalog\Model\ResourceModel\Product\Fulltext\Collection->getFacetedData('option_text_per...')
#21 /var/www/html/vendor/magento/module-catalog/Model/Layer/Filter/AbstractFilter.php(202): Smile\ElasticsuiteCatalog\Model\Layer\Filter\Attribute->_getItemsData()
#22 /var/www/html/vendor/smile/elasticsuite/src/module-elasticsuite-catalog/Model/Layer/Filter/Attribute.php(175): Magento\Catalog\Model\Layer\Filter\AbstractFilter->_initItems()
#23 /var/www/html/vendor/magento/module-catalog/Model/Layer/Filter/AbstractFilter.php(159): Smile\ElasticsuiteCatalog\Model\Layer\Filter\Attribute->_initItems()
#24 /var/www/html/vendor/magento/module-catalog/Model/Layer/Filter/AbstractFilter.php(148): Magento\Catalog\Model\Layer\Filter\AbstractFilter->getItems()
#25 /var/www/html/vendor/magento/module-catalog/Model/Layer/Category/AvailabilityFlag.php(33): Magento\Catalog\Model\Layer\Filter\AbstractFilter->getItemsCount()
#26 /var/www/html/vendor/magento/module-catalog/Model/Layer/Category/AvailabilityFlag.php(23): Magento\Catalog\Model\Layer\Category\AvailabilityFlag->canShowOptions(Array)
#27 /var/www/html/vendor/magento/module-layered-navigation/Block/Navigation.php(126): Magento\Catalog\Model\Layer\Category\AvailabilityFlag->isEnabled(Object(Magento\Catalog\Model\Layer\Category\Interceptor), Array)
#28 /var/www/html/vendor/smile/elasticsuite/src/module-elasticsuite-catalog/Block/Navigation.php(83): Magento\LayeredNavigation\Block\Navigation->canShowBlock()
#0 [internal function]: Smile\ElasticsuiteVirtualCategory\Model\Rule->getCategorySearchQuery(Object(Magento\Catalog\Model\Category\Interceptor))
#1 /var/www/html/vendor/smile/elasticsuite/src/module-elasticsuite-virtual-category/Helper/Rule.php(110): call_user_func_array(Array, Array)
#2 /var/www/html/vendor/smile/elasticsuite/src/module-elasticsuite-virtual-category/Model/Category/Filter/Provider.php(87): Smile\ElasticsuiteVirtualCategory\Helper\Rule->loadUsingCache(Object(Magento\Catalog\Model\Category\Interceptor), 'getCategorySear...')
#3 /var/www/html/vendor/smile/elasticsuite/src/module-elasticsuite-virtual-category/Model/Category/Filter/Provider.php(70): Smile\ElasticsuiteVirtualCategory\Model\Category\Filter\Provider->getCategorySearchQuery(Object(Magento\Catalog\Model\Category\Interceptor))
#4 /var/www/html/vendor/smile/elasticsuite/src/module-elasticsuite-catalog/Model/Product/Search/Request/Container/Filter/CurrentCategory.php(70): Smile\ElasticsuiteVirtualCategory\Model\Category\Filter\Provider->getQueryFilter(Object(Magento\Catalog\Model\Category\Interceptor))
#5 /var/www/html/vendor/smile/elasticsuite/src/module-elasticsuite-core/Search/Request/ContainerConfiguration.php(139): Smile\ElasticsuiteCatalog\Model\Product\Search\Request\Container\Filter\CurrentCategory->getFilterQuery()
#6 /var/www/html/vendor/smile/elasticsuite/src/module-elasticsuite-core/Search/Request/Builder.php(207): Smile\ElasticsuiteCore\Search\Request\ContainerConfiguration->getFilters()
#7 /var/www/html/vendor/smile/elasticsuite/src/module-elasticsuite-core/Search/Request/Builder.php(149): Smile\ElasticsuiteCore\Search\Request\Builder->getContainerFilters(Object(Smile\ElasticsuiteCore\Search\Request\ContainerConfiguration))
#8 /var/www/html/vendor/magento/framework/Interception/Interceptor.php(58): Smile\ElasticsuiteCore\Search\Request\Builder->create(7, 'catalog_view_co...', 0, 0, NULL, Array, Array, Array, Array)
#9 /var/www/html/vendor/magento/framework/Interception/Interceptor.php(138): Smile\ElasticsuiteCore\Search\Request\Builder\Interceptor->___callParent('create', Array)
#10 /var/www/html/vendor/magento/framework/Interception/Interceptor.php(153): Smile\ElasticsuiteCore\Search\Request\Builder\Interceptor->Magento\Framework\Interception\{closure}(7, 'catalog_view_co...', 0, 0, NULL, Array, Array, Array, Array, true)
#11 /var/www/html/generated/code/Smile/ElasticsuiteCore/Search/Request/Builder/Interceptor.php(23): Smile\ElasticsuiteCore\Search\Request\Builder\Interceptor->___callPlugins('create', Array, Array)
#12 /var/www/html/vendor/smile/elasticsuite/src/module-elasticsuite-catalog/Model/ResourceModel/Product/Fulltext/Collection.php(631): Smile\ElasticsuiteCore\Search\Request\Builder\Interceptor->create(7, 'catalog_view_co...', 0, 0, NULL, Array, Array, Array, Array, true)
#13 /var/www/html/vendor/smile/elasticsuite/src/module-elasticsuite-catalog/Model/ResourceModel/Product/Fulltext/Collection.php(195): Smile\ElasticsuiteCatalog\Model\ResourceModel\Product\Fulltext\Collection->loadProductCounts()
#14 /var/www/html/vendor/smile/elasticsuite/src/module-elasticsuite-catalog/Model/ResourceModel/Product/Fulltext/Collection.php(489): Smile\ElasticsuiteCatalog\Model\ResourceModel\Product\Fulltext\Collection->getSize()
#15 /var/www/html/vendor/smile/elasticsuite/src/module-elasticsuite-catalog/Model/ResourceModel/Product/Fulltext/Collection.php(676): Smile\ElasticsuiteCatalog\Model\ResourceModel\Product\Fulltext\Collection->getPageSize()
#16 /var/www/html/vendor/smile/elasticsuite/src/module-elasticsuite-catalog/Model/ResourceModel/Product/Fulltext/Collection.php(519): Smile\ElasticsuiteCatalog\Model\ResourceModel\Product\Fulltext\Collection->prepareRequest()
#17 /var/www/html/vendor/magento/framework/Data/Collection/AbstractDb.php(542): Smile\ElasticsuiteCatalog\Model\ResourceModel\Product\Fulltext\Collection->_renderFiltersBefore()
#18 /var/www/html/vendor/smile/elasticsuite/src/module-elasticsuite-catalog/Model/ResourceModel/Product/Fulltext/Collection.php(574): Magento\Framework\Data\Collection\AbstractDb->_renderFilters()
#19 /var/www/html/vendor/smile/elasticsuite/src/module-elasticsuite-catalog/Model/ResourceModel/Product/Fulltext/Collection.php(382): Smile\ElasticsuiteCatalog\Model\ResourceModel\Product\Fulltext\Collection->_renderFilters()
#20 /var/www/html/vendor/smile/elasticsuite/src/module-elasticsuite-catalog/Model/Layer/Filter/Attribute.php(139): Smile\ElasticsuiteCatalog\Model\ResourceModel\Product\Fulltext\Collection->getFacetedData('option_text_per...')
#21 /var/www/html/vendor/magento/module-catalog/Model/Layer/Filter/AbstractFilter.php(202): Smile\ElasticsuiteCatalog\Model\Layer\Filter\Attribute->_getItemsData()
#22 /var/www/html/vendor/smile/elasticsuite/src/module-elasticsuite-catalog/Model/Layer/Filter/Attribute.php(175): Magento\Catalog\Model\Layer\Filter\AbstractFilter->_initItems()
#23 /var/www/html/vendor/magento/module-catalog/Model/Layer/Filter/AbstractFilter.php(159): Smile\ElasticsuiteCatalog\Model\Layer\Filter\Attribute->_initItems()
#24 /var/www/html/vendor/magento/module-catalog/Model/Layer/Filter/AbstractFilter.php(148): Magento\Catalog\Model\Layer\Filter\AbstractFilter->getItems()
#25 /var/www/html/vendor/magento/module-catalog/Model/Layer/Category/AvailabilityFlag.php(33): Magento\Catalog\Model\Layer\Filter\AbstractFilter->getItemsCount()
#26 /var/www/html/vendor/magento/module-catalog/Model/Layer/Category/AvailabilityFlag.php(23): Magento\Catalog\Model\Layer\Category\AvailabilityFlag->canShowOptions(Array)
#27 /var/www/html/vendor/magento/module-layered-navigation/Block/Navigation.php(126): Magento\Catalog\Model\Layer\Category\AvailabilityFlag->isEnabled(Object(Magento\Catalog\Model\Layer\Category\Interceptor), Array)
#28 /var/www/html/vendor/smile/elasticsuite/src/module-elasticsuite-catalog/Block/Navigation.php(83): Magento\LayeredNavigation\Block\Navigation->canShowBlock()

I'm not sure what fix would be best here.

We'll reapply our fix to solve that. But I thought you would want to know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants