Skip to content

Commit ec81173

Browse files
authored
Merge pull request #2528 from magento-performance/MAGETWO-88670
[Performance] MAGETWO-88670: Catalog EAV table getting called instead of flat table on top menu when flat is enabled
2 parents 6950ccf + 4ab3e9a commit ec81173

File tree

3 files changed

+59
-4
lines changed

3 files changed

+59
-4
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
namespace Magento\Catalog\Model\ResourceModel\Category;
8+
9+
/**
10+
* Factory class for state dependent category collection
11+
*/
12+
class StateDependentCollectionFactory
13+
{
14+
/**
15+
* Object Manager instance
16+
*
17+
* @var \Magento\Framework\ObjectManagerInterface
18+
*/
19+
private $objectManager;
20+
21+
/**
22+
* Catalog category flat state
23+
*
24+
* @var \Magento\Catalog\Model\Indexer\Category\Flat\State
25+
*/
26+
private $catalogCategoryFlatState;
27+
28+
/**
29+
* Factory constructor
30+
*
31+
* @param \Magento\Framework\ObjectManagerInterface $objectManager
32+
* @param \Magento\Catalog\Model\Indexer\Category\Flat\State $catalogCategoryFlatState
33+
*/
34+
public function __construct(
35+
\Magento\Framework\ObjectManagerInterface $objectManager,
36+
\Magento\Catalog\Model\Indexer\Category\Flat\State $catalogCategoryFlatState
37+
) {
38+
$this->objectManager = $objectManager;
39+
$this->catalogCategoryFlatState = $catalogCategoryFlatState;
40+
}
41+
42+
/**
43+
* Create class instance with specified parameters
44+
*
45+
* @param array $data
46+
* @return \Magento\Framework\Data\Collection\AbstractDb
47+
*/
48+
public function create(array $data = [])
49+
{
50+
return $this->objectManager->create(
51+
($this->catalogCategoryFlatState->isAvailable()) ? Flat\Collection::class : Collection::class,
52+
$data
53+
);
54+
}
55+
}

app/code/Magento/Catalog/Plugin/Block/Topmenu.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class Topmenu
2222
protected $catalogCategory;
2323

2424
/**
25-
* @var \Magento\Catalog\Model\ResourceModel\Category\CollectionFactory
25+
* @var \Magento\Catalog\Model\ResourceModel\Category\StateDependentCollectionFactory
2626
*/
2727
private $collectionFactory;
2828

@@ -40,13 +40,13 @@ class Topmenu
4040
* Initialize dependencies.
4141
*
4242
* @param \Magento\Catalog\Helper\Category $catalogCategory
43-
* @param \Magento\Catalog\Model\ResourceModel\Category\CollectionFactory $categoryCollectionFactory
43+
* @param \Magento\Catalog\Model\ResourceModel\Category\StateDependentCollectionFactory $categoryCollectionFactory
4444
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
4545
* @param \Magento\Catalog\Model\Layer\Resolver $layerResolver
4646
*/
4747
public function __construct(
4848
\Magento\Catalog\Helper\Category $catalogCategory,
49-
\Magento\Catalog\Model\ResourceModel\Category\CollectionFactory $categoryCollectionFactory,
49+
\Magento\Catalog\Model\ResourceModel\Category\StateDependentCollectionFactory $categoryCollectionFactory,
5050
\Magento\Store\Model\StoreManagerInterface $storeManager,
5151
\Magento\Catalog\Model\Layer\Resolver $layerResolver
5252
) {

app/code/Magento/Catalog/Test/Unit/Plugin/Block/TopmenuTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ protected function setUp()
8787
\Magento\Catalog\Model\ResourceModel\Category\Collection::class
8888
);
8989
$this->categoryCollectionFactoryMock = $this->createPartialMock(
90-
\Magento\Catalog\Model\ResourceModel\Category\CollectionFactory::class,
90+
\Magento\Catalog\Model\ResourceModel\Category\StateDependentCollectionFactory::class,
9191
['create']
9292
);
9393

0 commit comments

Comments
 (0)