Skip to content

Commit 943eba9

Browse files
authored
Merge pull request #1312 from algolia/feat/INTEG-492
HOTFIX FOR 3.10.0 - INTEG-492: Add category lookup cache by store scope
2 parents 2a4e068 + 0ea139d commit 943eba9

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

Helper/Entity/CategoryHelper.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ class CategoryHelper
5050
protected $categoryRepository;
5151

5252
protected $isCategoryVisibleInMenuCache;
53+
protected $coreCategories;
5354
protected $idColumn;
5455
protected $categoryAttributes;
5556
protected $rootCategoryId = -1;
@@ -548,7 +549,12 @@ public function isCategoryVisibleInMenu($categoryId, $storeId)
548549
*/
549550
public function getCoreCategories($filterNotIncludedCategories = true, $storeId = null)
550551
{
551-
$key = $filterNotIncludedCategories ? 'filtered' : 'non_filtered';
552+
// Cache category look up by store scope
553+
$key = ($filterNotIncludedCategories ? 'filtered' : 'non_filtered') . "-$storeId";
554+
555+
if (isset($this->coreCategories[$key])) {
556+
return $this->coreCategories[$key];
557+
}
552558

553559
$collection = $this->categoryCollectionFactory->create()
554560
->distinct(true)
@@ -562,14 +568,14 @@ public function getCoreCategories($filterNotIncludedCategories = true, $storeId
562568
$collection->addAttributeToFilter('include_in_menu', '1');
563569
}
564570

565-
$coreCategories[$key] = [];
571+
$this->coreCategories[$key] = [];
566572

567573
/** @var \Magento\Catalog\Model\Category $category */
568574
foreach ($collection as $category) {
569-
$coreCategories[$key][$category->getId()] = $category;
575+
$this->coreCategories[$key][$category->getId()] = $category;
570576
}
571577

572-
return $coreCategories[$key];
578+
return $this->coreCategories[$key];
573579
}
574580

575581
/**

0 commit comments

Comments
 (0)