Skip to content

Commit

Permalink
[Virtual Category] Optimize virtual category rule computation
Browse files Browse the repository at this point in the history
Don't calculate virtual category root if parent category of the root category has been computed.
  • Loading branch information
PierreGauthier committed Jul 16, 2024
1 parent c8e4ce9 commit 14c08fc
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/module-elasticsuite-virtual-category/Model/Rule.php
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,16 @@ private function getVirtualCategoryQuery(
$excludedCategories = []
): ?QueryInterface {
$rootCategory = $this->getVirtualRootCategory($category);
if ($rootCategory && in_array($rootCategory->getId(), $excludedCategories)) {
// If the root category of the current virtual category has already been computed (exist in $excludedCategories)
// or if a parent of the root category of the current category has already been computed we don't need
// to compute the rule. All the product will already been present.
// For example, if you have the following category tree:
// - Category A (static)
// - - Category B (static)
// - - Category C (virtual with category B as root)
// When you compute the rule of the category A you do not need to compute the rule of the category C
// as all the product will be there.
if ($rootCategory && array_intersect(explode('/', $rootCategory->getPath()), $excludedCategories)) {
return null;
}

Expand Down

0 comments on commit 14c08fc

Please sign in to comment.