Skip to content

Commit c69f2a6

Browse files
Merge branch 'develop' of https://github.com/magento-performance/magento2ce into MAGETWO-69130
2 parents 4d871db + 2992ee2 commit c69f2a6

File tree

117 files changed

+746
-1853
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

117 files changed

+746
-1853
lines changed

app/code/Magento/Bundle/Model/ResourceModel/Selection/Collection.php

Lines changed: 1 addition & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -44,99 +44,6 @@ class Collection extends \Magento\Catalog\Model\ResourceModel\Product\Collection
4444
*/
4545
private $websiteScopePriceJoined = false;
4646

47-
/**
48-
* @var \Magento\Indexer\Model\ResourceModel\FrontendResource
49-
*/
50-
private $indexerStockFrontendResource;
51-
52-
/**
53-
* Collection constructor.
54-
* @param \Magento\Framework\Data\Collection\EntityFactory $entityFactory
55-
* @param \Psr\Log\LoggerInterface $logger
56-
* @param \Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy
57-
* @param \Magento\Framework\Event\ManagerInterface $eventManager
58-
* @param \Magento\Eav\Model\Config $eavConfig
59-
* @param \Magento\Framework\App\ResourceConnection $resource
60-
* @param \Magento\Eav\Model\EntityFactory $eavEntityFactory
61-
* @param \Magento\Catalog\Model\ResourceModel\Helper $resourceHelper
62-
* @param \Magento\Framework\Validator\UniversalFactory $universalFactory
63-
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
64-
* @param \Magento\Framework\Module\Manager $moduleManager
65-
* @param \Magento\Catalog\Model\Indexer\Product\Flat\State $catalogProductFlatState
66-
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
67-
* @param \Magento\Catalog\Model\Product\OptionFactory $productOptionFactory
68-
* @param \Magento\Catalog\Model\ResourceModel\Url $catalogUrl
69-
* @param \Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate
70-
* @param \Magento\Customer\Model\Session $customerSession
71-
* @param \Magento\Framework\Stdlib\DateTime $dateTime
72-
* @param GroupManagementInterface $groupManagement
73-
* @param \Magento\Framework\DB\Adapter\AdapterInterface|null $connection
74-
* @param ProductLimitationFactory|null $productLimitationFactory
75-
* @param MetadataPool|null $metadataPool
76-
* @param \Magento\Indexer\Model\ResourceModel\FrontendResource|null $indexerFrontendResource
77-
* @param \Magento\Indexer\Model\ResourceModel\FrontendResource|null $categoryProductIndexerFrontend
78-
* @param \Magento\Indexer\Model\ResourceModel\FrontendResource|null $indexerStockFrontendResource
79-
*
80-
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
81-
* @SuppressWarnings(Magento.TypeDuplication)
82-
*/
83-
public function __construct(
84-
\Magento\Framework\Data\Collection\EntityFactory $entityFactory,
85-
\Psr\Log\LoggerInterface $logger,
86-
\Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy,
87-
\Magento\Framework\Event\ManagerInterface $eventManager,
88-
\Magento\Eav\Model\Config $eavConfig,
89-
\Magento\Framework\App\ResourceConnection $resource,
90-
\Magento\Eav\Model\EntityFactory $eavEntityFactory,
91-
\Magento\Catalog\Model\ResourceModel\Helper $resourceHelper,
92-
\Magento\Framework\Validator\UniversalFactory $universalFactory,
93-
\Magento\Store\Model\StoreManagerInterface $storeManager,
94-
\Magento\Framework\Module\Manager $moduleManager,
95-
\Magento\Catalog\Model\Indexer\Product\Flat\State $catalogProductFlatState,
96-
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
97-
\Magento\Catalog\Model\Product\OptionFactory $productOptionFactory,
98-
\Magento\Catalog\Model\ResourceModel\Url $catalogUrl,
99-
\Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate,
100-
\Magento\Customer\Model\Session $customerSession,
101-
\Magento\Framework\Stdlib\DateTime $dateTime,
102-
GroupManagementInterface $groupManagement,
103-
\Magento\Framework\DB\Adapter\AdapterInterface $connection = null,
104-
ProductLimitationFactory $productLimitationFactory = null,
105-
MetadataPool $metadataPool = null,
106-
\Magento\Indexer\Model\ResourceModel\FrontendResource $indexerFrontendResource = null,
107-
\Magento\Indexer\Model\ResourceModel\FrontendResource $categoryProductIndexerFrontend = null,
108-
\Magento\Indexer\Model\ResourceModel\FrontendResource $indexerStockFrontendResource = null
109-
) {
110-
parent::__construct(
111-
$entityFactory,
112-
$logger,
113-
$fetchStrategy,
114-
$eventManager,
115-
$eavConfig,
116-
$resource,
117-
$eavEntityFactory,
118-
$resourceHelper,
119-
$universalFactory,
120-
$storeManager,
121-
$moduleManager,
122-
$catalogProductFlatState,
123-
$scopeConfig,
124-
$productOptionFactory,
125-
$catalogUrl,
126-
$localeDate,
127-
$customerSession,
128-
$dateTime,
129-
$groupManagement,
130-
$connection,
131-
$productLimitationFactory,
132-
$metadataPool,
133-
$indexerFrontendResource,
134-
$categoryProductIndexerFrontend
135-
);
136-
$this->indexerStockFrontendResource = $indexerStockFrontendResource ?: ObjectManager::getInstance()
137-
->get(\Magento\CatalogInventory\Model\ResourceModel\Indexer\Stock\FrontendResource::class);
138-
}
139-
14047
/**
14148
* Initialize collection
14249
*
@@ -261,7 +168,7 @@ public function addQuantityFilter()
261168
{
262169
$this->getSelect()
263170
->joinInner(
264-
['stock' => $this->indexerStockFrontendResource->getMainTable()],
171+
['stock' => $this->getTable('cataloginventory_stock_status')],
265172
'selection.product_id = stock.product_id',
266173
[]
267174
)

app/code/Magento/Bundle/Test/Unit/Model/ResourceModel/Selection/CollectionTest.php

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
namespace Magento\Bundle\Test\Unit\Model\ResourceModel\Selection;
77

88
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
9-
use Magento\Indexer\Model\ResourceModel\FrontendResource;
109
use Magento\Store\Model\StoreManagerInterface;
1110
use Magento\Store\Api\Data\StoreInterface;
1211
use Magento\Framework\Validator\UniversalFactory;
@@ -17,15 +16,9 @@
1716

1817
/**
1918
* Class CollectionTest.
20-
* Unit test for \Magento\Indexer\Model\ResourceModel\FrontendResource.
2119
*/
2220
class CollectionTest extends \PHPUnit_Framework_TestCase
2321
{
24-
/**
25-
* @var \PHPUnit_Framework_MockObject_MockObject
26-
*/
27-
private $frontendResource;
28-
2922
/**
3023
* @var \PHPUnit_Framework_MockObject_MockObject
3124
*/
@@ -64,9 +57,6 @@ class CollectionTest extends \PHPUnit_Framework_TestCase
6457
protected function setUp()
6558
{
6659
$objectManager = new ObjectManager($this);
67-
$this->frontendResource = $this->getMockBuilder(FrontendResource::class)
68-
->disableOriginalConstructor()
69-
->getMock();
7060
$this->storeManager = $this->getMockBuilder(StoreManagerInterface::class)
7161
->disableOriginalConstructor()
7262
->getMock();
@@ -114,17 +104,16 @@ protected function setUp()
114104
[
115105
'storeManager' => $this->storeManager,
116106
'universalFactory' => $this->universalFactory,
117-
'productLimitationFactory' => $factory,
118-
'indexerStockFrontendResource' => $this->frontendResource
107+
'productLimitationFactory' => $factory
119108
]
120109
);
121110
}
122111

123112
public function testAddQuantityFilter()
124113
{
125114
$tableName = 'cataloginventory_stock_status';
126-
$this->frontendResource->expects($this->once())
127-
->method('getMainTable')
115+
$this->entity->expects($this->once())
116+
->method('getTable')
128117
->willReturn($tableName);
129118
$this->select->expects($this->once())
130119
->method('joinInner')

app/code/Magento/Bundle/composer.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@
1818
"magento/framework": "100.2.*",
1919
"magento/module-quote": "100.2.*",
2020
"magento/module-media-storage": "100.2.*",
21-
"magento/module-ui": "100.2.*",
22-
"magento/module-indexer": "100.2.*"
21+
"magento/module-ui": "100.2.*"
2322
},
2423
"suggest": {
2524
"magento/module-webapi": "100.2.*",

app/code/Magento/Bundle/etc/di.xml

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -155,19 +155,9 @@
155155
</type>
156156
<type name="Magento\CatalogInventory\Model\Indexer\Stock\Action\Full">
157157
<arguments>
158-
<argument name="memoryTablesMinRows" xsi:type="array">
158+
<argument name="batchRowsCount" xsi:type="array">
159159
<item name="bundle" xsi:type="number">136</item>
160160
</argument>
161161
</arguments>
162162
</type>
163-
<type name="Magento\Bundle\Model\ResourceModel\Selection\Collection">
164-
<arguments>
165-
<argument name="indexerStockFrontendResource" xsi:type="object">Magento\CatalogInventory\Model\ResourceModel\Indexer\Stock\FrontendResource</argument>
166-
</arguments>
167-
</type>
168-
<type name="Magento\Bundle\Model\ResourceModel\Indexer\Stock">
169-
<arguments>
170-
<argument name="indexerStockFrontendResource" xsi:type="object">Magento\CatalogInventory\Model\ResourceModel\Indexer\Stock\FrontendResource</argument>
171-
</arguments>
172-
</type>
173163
</config>

app/code/Magento/Catalog/Model/Indexer/Category/Product/AbstractAction.php

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
use Magento\Framework\DB\Query\Generator as QueryGenerator;
1212
use Magento\Framework\App\ResourceConnection;
1313
use Magento\Framework\EntityManager\MetadataPool;
14-
use Magento\Catalog\Model\ResourceModel\Product\Indexer\Category\Product\FrontendResource as CategoryProductFrontend;
1514

1615
/**
1716
* Class AbstractAction
@@ -112,33 +111,24 @@ abstract class AbstractAction
112111
*/
113112
private $queryGenerator;
114113

115-
/**
116-
* @var \Magento\Indexer\Model\ResourceModel\FrontendResource|null
117-
*/
118-
private $categoryProductIndexerFrontend;
119-
120114
/**
121115
* @param ResourceConnection $resource
122116
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
123117
* @param \Magento\Catalog\Model\Config $config
124118
* @param QueryGenerator $queryGenerator
125-
* @param \Magento\Indexer\Model\ResourceModel\FrontendResource|null $categoryProductIndexerFrontend
126119
*/
127120
public function __construct(
128121
\Magento\Framework\App\ResourceConnection $resource,
129122
\Magento\Store\Model\StoreManagerInterface $storeManager,
130123
\Magento\Catalog\Model\Config $config,
131-
QueryGenerator $queryGenerator = null,
132-
\Magento\Indexer\Model\ResourceModel\FrontendResource $categoryProductIndexerFrontend = null
124+
QueryGenerator $queryGenerator = null
133125
) {
134126
$this->resource = $resource;
135127
$this->connection = $resource->getConnection();
136128
$this->storeManager = $storeManager;
137129
$this->config = $config;
138130
$this->queryGenerator = $queryGenerator ?: \Magento\Framework\App\ObjectManager::getInstance()
139131
->get(QueryGenerator::class);
140-
$this->categoryProductIndexerFrontend = $categoryProductIndexerFrontend
141-
?: \Magento\Framework\App\ObjectManager::getInstance()->get(CategoryProductFrontend::class);
142132
}
143133

144134
/**
@@ -185,7 +175,7 @@ protected function getTable($table)
185175
*/
186176
protected function getMainTable()
187177
{
188-
return $this->categoryProductIndexerFrontend->getMainTable();
178+
return $this->getTable(self::MAIN_INDEX_TABLE);
189179
}
190180

191181
/**

app/code/Magento/Catalog/Model/Indexer/Category/Product/Action/Full.php

Lines changed: 13 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66
namespace Magento\Catalog\Model\Indexer\Category\Product\Action;
77

8+
use Magento\Catalog\Model\ResourceModel\Indexer\ActiveTableSwitcher;
89
use Magento\Framework\DB\Query\Generator as QueryGenerator;
910
use Magento\Framework\App\ResourceConnection;
1011

@@ -26,11 +27,6 @@ class Full extends \Magento\Catalog\Model\Indexer\Category\Product\AbstractActio
2627
*/
2728
private $batchProvider;
2829

29-
/**
30-
* @var \Magento\Indexer\Model\Indexer\StateFactory
31-
*/
32-
private $indexerStateFactory;
33-
3430
/**
3531
* @var \Magento\Framework\EntityManager\MetadataPool
3632
*/
@@ -43,6 +39,11 @@ class Full extends \Magento\Catalog\Model\Indexer\Category\Product\AbstractActio
4339
*/
4440
private $batchRowsCount;
4541

42+
/**
43+
* @var ActiveTableSwitcher
44+
*/
45+
private $activeTableSwitcher;
46+
4647
/**
4748
* @param ResourceConnection $resource
4849
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
@@ -53,6 +54,7 @@ class Full extends \Magento\Catalog\Model\Indexer\Category\Product\AbstractActio
5354
* @param \Magento\Framework\EntityManager\MetadataPool|null $metadataPool
5455
* @param \Magento\Indexer\Model\Indexer\StateFactory|null $stateFactory
5556
* @param int|null $batchRowsCount
57+
* @param ActiveTableSwitcher|null $activeTableSwitcher
5658
*/
5759
public function __construct(
5860
\Magento\Framework\App\ResourceConnection $resource,
@@ -62,8 +64,8 @@ public function __construct(
6264
\Magento\Framework\Indexer\BatchSizeManagementInterface $batchSizeManagement = null,
6365
\Magento\Framework\Indexer\BatchProviderInterface $batchProvider = null,
6466
\Magento\Framework\EntityManager\MetadataPool $metadataPool = null,
65-
\Magento\Indexer\Model\Indexer\StateFactory $stateFactory = null,
66-
$batchRowsCount = null
67+
$batchRowsCount = null,
68+
ActiveTableSwitcher $activeTableSwitcher = null
6769
) {
6870
parent::__construct(
6971
$resource,
@@ -81,10 +83,8 @@ public function __construct(
8183
$this->metadataPool = $metadataPool ?: $objectManager->get(
8284
\Magento\Framework\EntityManager\MetadataPool::class
8385
);
84-
$this->indexerStateFactory = $stateFactory ?: $objectManager->get(
85-
\Magento\Indexer\Model\Indexer\StateFactory::class
86-
);
8786
$this->batchRowsCount = $batchRowsCount;
87+
$this->activeTableSwitcher = $activeTableSwitcher ?: $objectManager->get(ActiveTableSwitcher::class);
8888
}
8989

9090
/**
@@ -95,7 +95,7 @@ public function __construct(
9595
public function execute()
9696
{
9797
$this->reindex();
98-
98+
$this->activeTableSwitcher->switchTable($this->connection, $this->getMainTable());
9999
return $this;
100100
}
101101

@@ -143,13 +143,13 @@ protected function removeUnnecessaryData()
143143
protected function publishData()
144144
{
145145
$select = $this->connection->select()->from($this->getMainTmpTable());
146-
147146
$columns = array_keys($this->connection->describeTable($this->getMainTable()));
147+
$tableName = $this->activeTableSwitcher->getAdditionalTableName($this->getMainTable());
148148

149149
$this->connection->query(
150150
$this->connection->insertFromSelect(
151151
$select,
152-
$this->getMainTable(),
152+
$tableName,
153153
$columns,
154154
\Magento\Framework\DB\Adapter\AdapterInterface::INSERT_ON_DUPLICATE
155155
)
@@ -236,24 +236,4 @@ private function reindexCategoriesBySelect(\Magento\Framework\DB\Select $basicSe
236236
$this->removeUnnecessaryData();
237237
}
238238
}
239-
240-
/**
241-
* This overridden method returns ALTERNATIVE table name to work with.
242-
*
243-
* When the table used on frontend is 'catalog_category_product_index' this indexer should work
244-
* with 'catalog_category_product_index_replica' and vice versa.
245-
*
246-
* @return string table name which is NOT used on frontend
247-
*/
248-
protected function getMainTable()
249-
{
250-
$table = $this->getTable(self::MAIN_INDEX_TABLE);
251-
$indexerState = $this->indexerStateFactory->create()->loadByIndexer(
252-
\Magento\Catalog\Model\Indexer\Category\Product::INDEXER_ID
253-
);
254-
$destinationTableSuffix = ($indexerState->getTableSuffix() === '')
255-
? \Magento\Framework\Indexer\StateInterface::ADDITIONAL_TABLE_SUFFIX
256-
: '';
257-
return $table . $destinationTableSuffix;
258-
}
259239
}

0 commit comments

Comments
 (0)