Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 17f9341

Browse files
authoredApr 11, 2018
Merge pull request #2359 from magento-performance/MAGETWO-90041
[performance] MAGETWO-90041: Changing the code structure for segmentation for Category Product Indexer
2 parents cabb18b + c75b5f0 commit 17f9341

File tree

15 files changed

+182
-116
lines changed

15 files changed

+182
-116
lines changed
 

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

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
use Magento\Framework\DB\Select;
1717
use Magento\Framework\EntityManager\MetadataPool;
1818
use Magento\Store\Model\Store;
19-
use Magento\Catalog\Model\Indexer\Category\Product\TableResolver;
19+
use Magento\Catalog\Model\Indexer\Category\Product\TableMaintainer;
2020

2121
/**
2222
* Class AbstractAction
@@ -40,7 +40,6 @@ abstract class AbstractAction
4040

4141
/**
4242
* Catalog category index table name
43-
* @deprecated
4443
*/
4544
const MAIN_INDEX_TABLE = 'catalog_category_product_index';
4645

@@ -112,9 +111,9 @@ abstract class AbstractAction
112111
protected $metadataPool;
113112

114113
/**
115-
* @var TableResolver
114+
* @var TableMaintainer
116115
*/
117-
protected $tableResolver;
116+
protected $tableMaintainer;
118117

119118
/**
120119
* @var string
@@ -133,23 +132,23 @@ abstract class AbstractAction
133132
* @param \Magento\Catalog\Model\Config $config
134133
* @param QueryGenerator $queryGenerator
135134
* @param MetadataPool|null $metadataPool
136-
* @param TableResolver|null $tableResolver
135+
* @param TableMaintainer|null $tableMaintainer
137136
*/
138137
public function __construct(
139138
\Magento\Framework\App\ResourceConnection $resource,
140139
\Magento\Store\Model\StoreManagerInterface $storeManager,
141140
\Magento\Catalog\Model\Config $config,
142141
QueryGenerator $queryGenerator = null,
143142
MetadataPool $metadataPool = null,
144-
TableResolver $tableResolver = null
143+
TableMaintainer $tableMaintainer = null
145144
) {
146145
$this->resource = $resource;
147146
$this->connection = $resource->getConnection();
148147
$this->storeManager = $storeManager;
149148
$this->config = $config;
150149
$this->queryGenerator = $queryGenerator ?: ObjectManager::getInstance()->get(QueryGenerator::class);
151150
$this->metadataPool = $metadataPool ?: ObjectManager::getInstance()->get(MetadataPool::class);
152-
$this->tableResolver = $tableResolver ?: ObjectManager::getInstance()->get(TableResolver::class);
151+
$this->tableMaintainer = $tableMaintainer ?: ObjectManager::getInstance()->get(TableMaintainer::class);
153152
}
154153

155154
/**
@@ -222,8 +221,8 @@ protected function getMainTmpTable()
222221
protected function getIndexTable($storeId)
223222
{
224223
return $this->useTempTable
225-
? $this->tableResolver->getMainReplicaTable($storeId)
226-
: $this->tableResolver->getMainTable($storeId);
224+
? $this->tableMaintainer->getMainReplicaTable($storeId)
225+
: $this->tableMaintainer->getMainTable($storeId);
227226
}
228227

229228
/**

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

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public function __construct(
102102
private function createTables()
103103
{
104104
foreach ($this->storeManager->getStores() as $store) {
105-
$this->tableResolver->createTablesForStore($store->getId());
105+
$this->tableMaintainer->createTablesForStore($store->getId());
106106
}
107107
}
108108

@@ -112,7 +112,7 @@ private function createTables()
112112
private function clearReplicaTables()
113113
{
114114
foreach ($this->storeManager->getStores() as $store) {
115-
$this->connection->truncateTable($this->tableResolver->getMainReplicaTable($store->getId()));
115+
$this->connection->truncateTable($this->tableMaintainer->getMainReplicaTable($store->getId()));
116116
}
117117
}
118118

@@ -123,7 +123,7 @@ private function switchTables()
123123
{
124124
$tablesToSwitch = [];
125125
foreach ($this->storeManager->getStores() as $store) {
126-
$tablesToSwitch[] = $this->tableResolver->getMainTable($store->getId());
126+
$tablesToSwitch[] = $this->tableMaintainer->getMainTable($store->getId());
127127
}
128128
$this->activeTableSwitcher->switchTable($this->connection, $tablesToSwitch);
129129
}
@@ -182,11 +182,11 @@ private function reindexStore($store)
182182
*/
183183
private function publishData($store)
184184
{
185-
$select = $this->connection->select()->from($this->tableResolver->getMainTmpTable($store->getId()));
185+
$select = $this->connection->select()->from($this->tableMaintainer->getMainTmpTable($store->getId()));
186186
$columns = array_keys(
187-
$this->connection->describeTable($this->tableResolver->getMainReplicaTable($store->getId()))
187+
$this->connection->describeTable($this->tableMaintainer->getMainReplicaTable($store->getId()))
188188
);
189-
$tableName = $this->tableResolver->getMainReplicaTable($store->getId());
189+
$tableName = $this->tableMaintainer->getMainReplicaTable($store->getId());
190190

191191
$this->connection->query(
192192
$this->connection->insertFromSelect(
@@ -240,8 +240,12 @@ protected function reindexNonAnchorCategories(\Magento\Store\Model\Store $store)
240240
*/
241241
private function reindexCategoriesBySelect(\Magento\Framework\DB\Select $basicSelect, $whereCondition, $store)
242242
{
243+
$this->tableMaintainer->createMainTmpTable($store->getId());
244+
243245
$entityMetadata = $this->metadataPool->getMetadata(\Magento\Catalog\Api\Data\ProductInterface::class);
244-
$columns = array_keys($this->connection->describeTable($this->tableResolver->getMainTmpTable($store->getId())));
246+
$columns = array_keys(
247+
$this->connection->describeTable($this->tableMaintainer->getMainTmpTable($store->getId()))
248+
);
245249
$this->batchSizeManagement->ensureBatchSize($this->connection, $this->batchRowsCount);
246250
$batches = $this->batchProvider->getBatches(
247251
$this->connection,
@@ -250,7 +254,7 @@ private function reindexCategoriesBySelect(\Magento\Framework\DB\Select $basicSe
250254
$this->batchRowsCount
251255
);
252256
foreach ($batches as $batch) {
253-
$this->connection->delete($this->tableResolver->getMainTmpTable($store->getId()));
257+
$this->connection->delete($this->tableMaintainer->getMainTmpTable($store->getId()));
254258
$resultSelect = clone $basicSelect;
255259
$select = $this->connection->select();
256260
$select->distinct(true);
@@ -260,7 +264,7 @@ private function reindexCategoriesBySelect(\Magento\Framework\DB\Select $basicSe
260264
$this->connection->query(
261265
$this->connection->insertFromSelect(
262266
$resultSelect,
263-
$this->tableResolver->getMainTmpTable($store->getId()),
267+
$this->tableMaintainer->getMainTmpTable($store->getId()),
264268
$columns,
265269
\Magento\Framework\DB\Adapter\AdapterInterface::INSERT_ON_DUPLICATE
266270
)

‎app/code/Magento/Catalog/Model/Indexer/Category/Product/Plugin/StoreGroup.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
use Magento\Framework\Model\AbstractModel;
1111
use Magento\Catalog\Model\Indexer\Category\Product;
1212
use Magento\Framework\App\ObjectManager;
13-
use Magento\Catalog\Model\Indexer\Category\Product\TableResolver;
13+
use Magento\Catalog\Model\Indexer\Category\Product\TableMaintainer;
1414

1515
class StoreGroup
1616
{
@@ -25,20 +25,20 @@ class StoreGroup
2525
protected $indexerRegistry;
2626

2727
/**
28-
* @var TableResolver
28+
* @var TableMaintainer
2929
*/
30-
protected $tableResolver;
30+
protected $tableMaintainer;
3131

3232
/**
3333
* @param IndexerRegistry $indexerRegistry
34-
* @param TableResolver $tableResolver
34+
* @param TableMaintainer $tableMaintainer
3535
*/
3636
public function __construct(
3737
IndexerRegistry $indexerRegistry,
38-
TableResolver $tableResolver = null
38+
TableMaintainer $tableMaintainer
3939
) {
4040
$this->indexerRegistry = $indexerRegistry;
41-
$this->tableResolver = $tableResolver ?: ObjectManager::getInstance()->get(TableResolver::class);
41+
$this->tableMaintainer = $tableMaintainer;
4242
}
4343

4444
/**
@@ -98,7 +98,7 @@ protected function validate(AbstractModel $group)
9898
public function afterDelete(AbstractDb $subject, AbstractDb $objectResource, AbstractModel $storeGroup)
9999
{
100100
foreach ($storeGroup->getStores() as $store) {
101-
$this->tableResolver->dropTablesForStore($store->getId());
101+
$this->tableMaintainer->dropTablesForStore($store->getId());
102102
}
103103
return $objectResource;
104104
}

‎app/code/Magento/Catalog/Model/Indexer/Category/Product/Plugin/StoreView.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ protected function validate(\Magento\Framework\Model\AbstractModel $store)
3333
public function afterSave(AbstractDb $subject, AbstractDb $objectResource, AbstractModel $store = null)
3434
{
3535
if ($store->isObjectNew()) {
36-
$this->tableResolver->createTablesForStore($store->getId());
36+
$this->tableMaintainer->createTablesForStore($store->getId());
3737
}
3838

3939
return parent::afterSave($subject, $objectResource);
@@ -51,7 +51,7 @@ public function afterSave(AbstractDb $subject, AbstractDb $objectResource, Abstr
5151
*/
5252
public function afterDelete(AbstractDb $subject, AbstractDb $objectResource, AbstractModel $store)
5353
{
54-
$this->tableResolver->dropTablesForStore($store->getId());
54+
$this->tableMaintainer->dropTablesForStore($store->getId());
5555
return $objectResource;
5656
}
5757
}

‎app/code/Magento/Catalog/Model/Indexer/Category/Product/Plugin/Website.php

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,22 @@
77

88
use Magento\Framework\Model\ResourceModel\Db\AbstractDb;
99
use Magento\Framework\Model\AbstractModel;
10-
use Magento\Framework\App\ObjectManager;
11-
use Magento\Catalog\Model\Indexer\Category\Product\TableResolver;
10+
use Magento\Catalog\Model\Indexer\Category\Product\TableMaintainer;
1211

1312
class Website
1413
{
1514
/**
16-
* @var TableResolver
15+
* @var TableMaintainer
1716
*/
18-
private $tableResolver;
17+
private $tableMaintainer;
1918

2019
/**
21-
* @param TableResolver $tableResolver
20+
* @param TableMaintainer $tableMaintainer
2221
*/
2322
public function __construct(
24-
TableResolver $tableResolver = null
23+
TableMaintainer $tableMaintainer
2524
) {
26-
$this->tableResolver = $tableResolver ?: ObjectManager::getInstance()->get(TableResolver::class);
25+
$this->tableMaintainer = $tableMaintainer;
2726
}
2827

2928
/**
@@ -39,7 +38,7 @@ public function __construct(
3938
public function afterDelete(AbstractDb $subject, AbstractDb $objectResource, AbstractModel $website)
4039
{
4140
foreach ($website->getStoreIds() as $storeId) {
42-
$this->tableResolver->dropTablesForStore($storeId);
41+
$this->tableMaintainer->dropTablesForStore($storeId);
4342
}
4443
return $objectResource;
4544
}

‎app/code/Magento/Catalog/Model/Indexer/Category/Product/TableResolver.php renamed to ‎app/code/Magento/Catalog/Model/Indexer/Category/Product/TableMaintainer.php

Lines changed: 67 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -4,55 +4,70 @@
44
* See COPYING.txt for license details.
55
*/
66

7+
declare(strict_types=1);
78
namespace Magento\Catalog\Model\Indexer\Category\Product;
89

9-
use Magento\Framework\Exception\LocalizedException;
10+
use Magento\Framework\App\ResourceConnection;
11+
use Magento\Framework\Search\Request\Dimension;
12+
use Magento\Framework\DB\Adapter\AdapterInterface;
13+
use Magento\Catalog\Model\Indexer\Category\Product\AbstractAction;
14+
use Magento\Framework\Indexer\ScopeResolver\IndexScopeResolver as TableResolver;
1015

11-
class TableResolver
16+
class TableMaintainer
1217
{
1318
/**
14-
* Catalog category index table name
19+
* @var ResourceConnection
1520
*/
16-
private $mainIndexTable = 'catalog_category_product_index';
21+
private $resource;
1722

1823
/**
19-
* Catalog category index store suffix
24+
* @var TableResolver
2025
*/
21-
private $mainIndexTableStoreSuffix = '_store_';
26+
private $tableResolver;
2227

2328
/**
24-
* Catalog tmp category index table name
29+
* @var AdapterInterface
2530
*/
26-
private $tmpTableSuffix = '_tmp';
31+
private $connection;
2732

2833
/**
2934
* Catalog tmp category index table name
3035
*/
31-
private $additionalTableSuffix = '_replica';
32-
33-
/**
34-
* @var \Magento\Framework\App\ResourceConnection
35-
*/
36-
private $resource;
36+
private $tmpTableSuffix = '_tmp';
3737

3838
/**
39-
* @var \Magento\Framework\DB\Adapter\AdapterInterface
39+
* Catalog tmp category index table name
4040
*/
41-
private $connection;
41+
private $additionalTableSuffix = '_replica';
4242

4343
/**
4444
* @var string[]
4545
*/
4646
private $mainTmpTable;
4747

4848
/**
49-
* @param \Magento\Framework\App\ResourceConnection $resource
49+
* @param ResourceConnection $resource
50+
* @param TableResolver $tableResolver
5051
*/
5152
public function __construct(
52-
\Magento\Framework\App\ResourceConnection $resource
53+
ResourceConnection $resource,
54+
TableResolver $tableResolver
5355
) {
5456
$this->resource = $resource;
55-
$this->connection = $resource->getConnection();
57+
$this->tableResolver = $tableResolver;
58+
}
59+
60+
/**
61+
* Get connection
62+
*
63+
* @return AdapterInterface
64+
*/
65+
private function getConnection()
66+
{
67+
if (!isset($this->connection)) {
68+
$this->connection = $this->resource->getConnection();
69+
}
70+
return $this->connection;
5671
}
5772

5873
/**
@@ -76,9 +91,9 @@ private function getTable($table)
7691
*/
7792
private function createTable($mainTableName, $newTableName)
7893
{
79-
if (!$this->connection->isTableExists($newTableName)) {
80-
$this->connection->createTable(
81-
$this->connection->createTableByDdl($mainTableName, $newTableName)
94+
if (!$this->getConnection()->isTableExists($newTableName)) {
95+
$this->getConnection()->createTable(
96+
$this->getConnection()->createTableByDdl($mainTableName, $newTableName)
8297
);
8398
}
8499
}
@@ -92,11 +107,25 @@ private function createTable($mainTableName, $newTableName)
92107
*/
93108
private function dropTable($tableName)
94109
{
95-
if ($this->connection->isTableExists($tableName)) {
96-
$this->connection->dropTable($tableName);
110+
if ($this->getConnection()->isTableExists($tableName)) {
111+
$this->getConnection()->dropTable($tableName);
97112
}
98113
}
99114

115+
/**
116+
* Return main index table name
117+
*
118+
* @param $storeId
119+
*
120+
* @return string
121+
*/
122+
public function getMainTable(int $storeId)
123+
{
124+
$catalogCategoryProductDimension = new Dimension(\Magento\Store\Model\Store::ENTITY, $storeId);
125+
126+
return $this->tableResolver->resolve(AbstractAction::MAIN_INDEX_TABLE, [$catalogCategoryProductDimension]);
127+
}
128+
100129
/**
101130
* Create main and replica index tables for store
102131
*
@@ -107,10 +136,10 @@ private function dropTable($tableName)
107136
public function createTablesForStore(int $storeId)
108137
{
109138
$mainTableName = $this->getMainTable($storeId);
110-
$this->createTable($this->getTable($this->mainIndexTable), $mainTableName);
139+
$this->createTable($this->getTable(AbstractAction::MAIN_INDEX_TABLE), $mainTableName);
111140

112141
$mainReplicaTableName = $this->getMainTable($storeId) . $this->additionalTableSuffix;
113-
$this->createTable($this->getTable($this->mainIndexTable), $mainReplicaTableName);
142+
$this->createTable($this->getTable(AbstractAction::MAIN_INDEX_TABLE), $mainReplicaTableName);
114143
}
115144

116145
/**
@@ -130,27 +159,32 @@ public function dropTablesForStore(int $storeId)
130159
}
131160

132161
/**
133-
* Return main index table name
162+
* Return replica index table name
134163
*
135164
* @param $storeId
136165
*
137166
* @return string
138167
*/
139-
public function getMainTable(int $storeId)
168+
public function getMainReplicaTable(int $storeId)
140169
{
141-
return $this->getTable($this->mainIndexTable) . $this->mainIndexTableStoreSuffix . $storeId;
170+
return $this->getMainTable($storeId) . $this->additionalTableSuffix;
142171
}
143172

144173
/**
145-
* Return replica index table name
174+
* Create temporary index table for store
146175
*
147176
* @param $storeId
148177
*
149-
* @return string
178+
* @return void
150179
*/
151-
public function getMainReplicaTable(int $storeId)
180+
public function createMainTmpTable(int $storeId)
152181
{
153-
return $this->getMainTable($storeId) . $this->additionalTableSuffix;
182+
if (!isset($this->mainTmpTable[$storeId])) {
183+
$originTableName = $this->getMainTable($storeId);
184+
$temporaryTableName = $this->getMainTable($storeId) . $this->tmpTableSuffix;
185+
$this->getConnection()->createTemporaryTableLike($temporaryTableName, $originTableName, true);
186+
$this->mainTmpTable[$storeId] = $temporaryTableName;
187+
}
154188
}
155189

156190
/**
@@ -162,12 +196,6 @@ public function getMainReplicaTable(int $storeId)
162196
*/
163197
public function getMainTmpTable(int $storeId)
164198
{
165-
if (!isset($this->mainTmpTable[$storeId])) {
166-
$originTableName = $this->getMainTable($storeId);
167-
$temporaryTableName = $this->getMainTable($storeId) . $this->tmpTableSuffix;
168-
$this->connection->createTemporaryTableLike($temporaryTableName, $originTableName, true);
169-
$this->mainTmpTable[$storeId] = $temporaryTableName;
170-
}
171199
return $this->mainTmpTable[$storeId];
172200
}
173201
}

‎app/code/Magento/Catalog/Model/ProductCategoryList.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
use Magento\Framework\DB\Sql\UnionExpression;
1111
use Magento\Framework\App\ObjectManager;
1212
use Magento\Store\Model\StoreManagerInterface;
13-
use Magento\Catalog\Model\Indexer\Category\Product\TableResolver;
13+
use Magento\Catalog\Model\Indexer\Category\Product\TableMaintainer;
1414

1515
/**
1616
* Provides info about product categories.
@@ -38,25 +38,25 @@ class ProductCategoryList
3838
private $storeManager;
3939

4040
/**
41-
* @var TableResolver
41+
* @var TableMaintainer
4242
*/
43-
private $tableResolver;
43+
private $tableMaintainer;
4444

4545
/**
4646
* @param ResourceModel\Product $productResource
4747
* @param ResourceModel\Category $category
4848
* @param StoreManagerInterface $storeManager
49-
* @param TableResolver|null $tableResolver
49+
* @param TableMaintainer|null $tableMaintainer
5050
*/
5151
public function __construct(
5252
ResourceModel\Product $productResource,
5353
ResourceModel\Category $category,
5454
StoreManagerInterface $storeManager = null,
55-
TableResolver $tableResolver = null
55+
TableMaintainer $tableMaintainer = null
5656
) {
5757
$this->productResource = $productResource;
5858
$this->category = $category;
59-
$this->tableResolver = $tableResolver ?: ObjectManager::getInstance()->get(TableResolver::class);
59+
$this->tableMaintainer = $tableMaintainer ?: ObjectManager::getInstance()->get(TableMaintainer::class);
6060
$this->storeManager = $storeManager ?: ObjectManager::getInstance()->get(StoreManagerInterface::class);
6161
}
6262

@@ -73,7 +73,7 @@ public function getCategoryIds($productId)
7373
foreach ($this->storeManager->getStores() as $store) {
7474
$unionTables[] = $this->getCategorySelect(
7575
$productId,
76-
$this->tableResolver->getMainTable($store->getId())
76+
$this->tableMaintainer->getMainTable($store->getId())
7777
);
7878
}
7979
$unionSelect = new UnionExpression(

‎app/code/Magento/Catalog/Model/ResourceModel/Product.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
use Magento\Catalog\Model\ResourceModel\Product\Website\Link as ProductWebsiteLink;
99
use Magento\Framework\App\ObjectManager;
10-
use Magento\Catalog\Model\Indexer\Category\Product\TableResolver;
10+
use Magento\Catalog\Model\Indexer\Category\Product\TableMaintainer;
1111

1212
/**
1313
* Product entity resource model
@@ -85,9 +85,9 @@ class Product extends AbstractResource
8585
private $productCategoryLink;
8686

8787
/**
88-
* @var TableResolver
88+
* @var TableMaintainer
8989
*/
90-
private $tableResolver;
90+
private $tableMaintainer;
9191

9292
/**
9393
* @param \Magento\Eav\Model\Entity\Context $context
@@ -100,7 +100,7 @@ class Product extends AbstractResource
100100
* @param \Magento\Eav\Model\Entity\TypeFactory $typeFactory
101101
* @param \Magento\Catalog\Model\Product\Attribute\DefaultAttributes $defaultAttributes
102102
* @param array $data
103-
* @param TableResolver|null $tableResolver
103+
* @param TableMaintainer|null $tableMaintainer
104104
*
105105
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
106106
*/
@@ -115,7 +115,7 @@ public function __construct(
115115
\Magento\Eav\Model\Entity\TypeFactory $typeFactory,
116116
\Magento\Catalog\Model\Product\Attribute\DefaultAttributes $defaultAttributes,
117117
$data = [],
118-
TableResolver $tableResolver = null
118+
TableMaintainer $tableMaintainer = null
119119
) {
120120
$this->_categoryCollectionFactory = $categoryCollectionFactory;
121121
$this->_catalogCategory = $catalogCategory;
@@ -130,7 +130,7 @@ public function __construct(
130130
$data
131131
);
132132
$this->connectionName = 'catalog';
133-
$this->tableResolver = $tableResolver ?: ObjectManager::getInstance()->get(TableResolver::class);
133+
$this->tableMaintainer = $tableMaintainer ?: ObjectManager::getInstance()->get(TableMaintainer::class);
134134
}
135135

136136
/**
@@ -377,7 +377,7 @@ public function getAvailableInCategories($object)
377377
if (!isset($this->availableCategoryIdsCache[$entityId])) {
378378
$this->availableCategoryIdsCache[$entityId] = $this->getConnection()->fetchCol(
379379
$this->getConnection()->select()->distinct()->from(
380-
$this->tableResolver->getMainTable($object->getStoreId()),
380+
$this->tableMaintainer->getMainTable($object->getStoreId()),
381381
['category_id']
382382
)->where(
383383
'product_id = ? AND is_parent = 1',
@@ -411,7 +411,7 @@ public function getDefaultAttributeSourceModel()
411411
public function canBeShowInCategory($product, $categoryId)
412412
{
413413
$select = $this->getConnection()->select()->from(
414-
$this->tableResolver->getMainTable($product->getStoreId()),
414+
$this->tableMaintainer->getMainTable($product->getStoreId()),
415415
'product_id'
416416
)->where(
417417
'product_id = ?',

‎app/code/Magento/Catalog/Model/ResourceModel/Product/Collection.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
use Magento\Framework\DB\Select;
1919
use Magento\Framework\EntityManager\MetadataPool;
2020
use Magento\Store\Model\Store;
21-
use Magento\Catalog\Model\Indexer\Category\Product\TableResolver;
21+
use Magento\Catalog\Model\Indexer\Category\Product\TableMaintainer;
2222

2323
/**
2424
* Product collection
@@ -274,9 +274,9 @@ class Collection extends \Magento\Catalog\Model\ResourceModel\Collection\Abstrac
274274
private $backend;
275275

276276
/**
277-
* @var TableResolver
277+
* @var TableMaintainer
278278
*/
279-
private $tableResolver;
279+
private $tableMaintainer;
280280

281281
/**
282282
* Collection constructor
@@ -303,7 +303,7 @@ class Collection extends \Magento\Catalog\Model\ResourceModel\Collection\Abstrac
303303
* @param \Magento\Framework\DB\Adapter\AdapterInterface|null $connection
304304
* @param ProductLimitationFactory|null $productLimitationFactory
305305
* @param MetadataPool|null $metadataPool
306-
* @param TableResolver|null $tableResolver
306+
* @param TableMaintainer|null $tableMaintainer
307307
*
308308
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
309309
*/
@@ -330,7 +330,7 @@ public function __construct(
330330
\Magento\Framework\DB\Adapter\AdapterInterface $connection = null,
331331
ProductLimitationFactory $productLimitationFactory = null,
332332
MetadataPool $metadataPool = null,
333-
TableResolver $tableResolver = null
333+
TableMaintainer $tableMaintainer = null
334334
) {
335335
$this->moduleManager = $moduleManager;
336336
$this->_catalogProductFlatState = $catalogProductFlatState;
@@ -360,7 +360,7 @@ public function __construct(
360360
$storeManager,
361361
$connection
362362
);
363-
$this->tableResolver = $tableResolver ?: ObjectManager::getInstance()->get(TableResolver::class);
363+
$this->tableMaintainer = $tableMaintainer ?: ObjectManager::getInstance()->get(TableMaintainer::class);
364364
}
365365

366366
/**
@@ -1201,7 +1201,7 @@ public function getProductCountSelect()
12011201
)->distinct(
12021202
false
12031203
)->join(
1204-
['count_table' => $this->tableResolver->getMainTable($this->getStoreId())],
1204+
['count_table' => $this->tableMaintainer->getMainTable($this->getStoreId())],
12051205
'count_table.product_id = e.entity_id',
12061206
[
12071207
'count_table.category_id',
@@ -1975,7 +1975,7 @@ protected function _applyProductLimitations()
19751975
$this->getSelect()->setPart(\Magento\Framework\DB\Select::FROM, $fromPart);
19761976
} else {
19771977
$this->getSelect()->join(
1978-
['cat_index' => $this->tableResolver->getMainTable($this->getStoreId())],
1978+
['cat_index' => $this->tableMaintainer->getMainTable($this->getStoreId())],
19791979
$joinCond,
19801980
['cat_index_position' => 'position']
19811981
);

‎app/code/Magento/Catalog/Model/ResourceModel/Url.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
use Magento\Catalog\Api\Data\CategoryInterface;
1515
use Magento\Framework\EntityManager\MetadataPool;
1616
use Magento\Framework\App\ObjectManager;
17-
use Magento\Catalog\Model\Indexer\Category\Product\TableResolver;
17+
use Magento\Catalog\Model\Indexer\Category\Product\TableMaintainer;
1818

1919
/**
2020
* Class Url
@@ -103,9 +103,9 @@ class Url extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb
103103
protected $metadataPool;
104104

105105
/**
106-
* @var TableResolver
106+
* @var TableMaintainer
107107
*/
108-
private $tableResolver;
108+
private $tableMaintainer;
109109

110110
/**
111111
* Url constructor.
@@ -116,7 +116,7 @@ class Url extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb
116116
* @param \Magento\Catalog\Model\Category $catalogCategory
117117
* @param \Psr\Log\LoggerInterface $logger
118118
* @param null $connectionName
119-
* @param TableResolver|null $tableResolver
119+
* @param TableMaintainer|null $tableMaintainer
120120
*/
121121
public function __construct(
122122
\Magento\Framework\Model\ResourceModel\Db\Context $context,
@@ -126,15 +126,15 @@ public function __construct(
126126
\Magento\Catalog\Model\Category $catalogCategory,
127127
\Psr\Log\LoggerInterface $logger,
128128
$connectionName = null,
129-
TableResolver $tableResolver = null
129+
TableMaintainer $tableMaintainer = null
130130
) {
131131
$this->_storeManager = $storeManager;
132132
$this->_eavConfig = $eavConfig;
133133
$this->productResource = $productResource;
134134
$this->_catalogCategory = $catalogCategory;
135135
$this->_logger = $logger;
136136
parent::__construct($context, $connectionName);
137-
$this->tableResolver = $tableResolver ?: ObjectManager::getInstance()->get(TableResolver::class);
137+
$this->tableMaintainer = $tableMaintainer ?: ObjectManager::getInstance()->get(TableMaintainer::class);
138138
}
139139

140140
/**
@@ -671,7 +671,7 @@ public function getRewriteByProductStore(array $products)
671671

672672
foreach ($storesProducts as $storeId => $productIds) {
673673
$select = $connection->select()->from(
674-
['i' => $this->tableResolver->getMainTable($storeId)],
674+
['i' => $this->tableMaintainer->getMainTable($storeId)],
675675
['product_id', 'store_id', 'visibility']
676676
)->joinLeft(
677677
['u' => $this->getMainTable()],

‎app/code/Magento/Catalog/Setup/UpgradeData.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -461,10 +461,15 @@ private function enableSegmentation(ModuleDataSetupInterface $setup)
461461
$store['store_id']
462462
);
463463

464+
$indexTable = $setup->getTable('catalog_category_product_index') .
465+
'_' .
466+
\Magento\Store\Model\Store::ENTITY .
467+
$store['store_id'];
468+
464469
$setup->getConnection()->query(
465470
$setup->getConnection()->insertFromSelect(
466471
$catalogCategoryProductIndexSelect,
467-
$setup->getTable('catalog_category_product_index') . '_store_' . $store['store_id'],
472+
$indexTable,
468473
$catalogCategoryProductIndexColumns,
469474
\Magento\Framework\DB\Adapter\AdapterInterface::INSERT_ON_DUPLICATE
470475
)

‎app/code/Magento/Catalog/Setup/UpgradeSchema.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -780,16 +780,21 @@ private function enableSegmentation(SchemaSetupInterface $setup)
780780
{
781781
$storeSelect = $setup->getConnection()->select()->from($setup->getTable('store'))->where('store_id > 0');
782782
foreach ($setup->getConnection()->fetchAll($storeSelect) as $store) {
783+
$indexTable = $setup->getTable('catalog_category_product_index') .
784+
'_' .
785+
\Magento\Store\Model\Store::ENTITY .
786+
$store['store_id'];
787+
783788
$setup->getConnection()->createTable(
784789
$setup->getConnection()->createTableByDdl(
785790
$setup->getTable('catalog_category_product_index'),
786-
$setup->getTable('catalog_category_product_index') . '_store_' . $store['store_id']
791+
$indexTable
787792
)
788793
);
789794
$setup->getConnection()->createTable(
790795
$setup->getConnection()->createTableByDdl(
791796
$setup->getTable('catalog_category_product_index'),
792-
$setup->getTable('catalog_category_product_index') . '_store_' . $store['store_id'] . '_replica'
797+
$indexTable . '_replica'
793798
)
794799
);
795800
}

‎app/code/Magento/Catalog/Test/Unit/Model/Indexer/Category/Product/Plugin/StoreViewTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ class StoreViewTest extends \PHPUnit\Framework\TestCase
3434
protected $indexerRegistryMock;
3535

3636
/**
37-
* @var \Magento\Catalog\Model\Indexer\Category\Product\TableResolver|\PHPUnit_Framework_MockObject_MockObject
37+
* @var \Magento\Catalog\Model\Indexer\Category\Product\TableMaintainer|\PHPUnit_Framework_MockObject_MockObject
3838
*/
39-
protected $tableResolver;
39+
protected $tableMaintainer;
4040

4141
/**
4242
* @var \PHPUnit_Framework_MockObject_MockObject
@@ -65,14 +65,14 @@ protected function setUp()
6565
'__wakeup'
6666
]
6767
);
68-
$this->tableResolver = $this->createPartialMock(
69-
\Magento\Catalog\Model\Indexer\Category\Product\TableResolver::class,
68+
$this->tableMaintainer = $this->createPartialMock(
69+
\Magento\Catalog\Model\Indexer\Category\Product\TableMaintainer::class,
7070
[
7171
'createTablesForStore'
7272
]
7373
);
7474

75-
$this->model = new StoreView($this->indexerRegistryMock, $this->tableResolver);
75+
$this->model = new StoreView($this->indexerRegistryMock, $this->tableMaintainer);
7676
}
7777

7878
public function testAroundSaveNewObject()

‎app/code/Magento/CatalogSearch/Model/Adapter/Mysql/Plugin/Aggregation/Category/DataProvider.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,12 @@
1313
use Magento\Framework\Search\Request\BucketInterface;
1414
use Magento\Framework\Search\Request\Dimension;
1515
use Magento\Framework\App\ObjectManager;
16-
use Magento\Catalog\Model\Indexer\Category\Product\TableResolver;
16+
use Magento\Framework\Indexer\ScopeResolver\IndexScopeResolver as TableResolver;
17+
use Magento\Catalog\Model\Indexer\Category\Product\AbstractAction;
1718

19+
/**
20+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
21+
*/
1822
class DataProvider
1923
{
2024
/**
@@ -79,9 +83,18 @@ public function aroundGetDataSet(
7983
$currentScopeId = $this->scopeResolver->getScope($dimensions['scope']->getValue())->getId();
8084
$currentCategory = $this->layer->getCurrentCategory();
8185

86+
$catalogCategoryProductDimension = new Dimension(\Magento\Store\Model\Store::ENTITY, $currentScopeId);
87+
88+
$catalogCategoryProductTableName = $this->tableResolver->resolve(
89+
AbstractAction::MAIN_INDEX_TABLE,
90+
[
91+
$catalogCategoryProductDimension
92+
]
93+
);
94+
8295
$derivedTable = $this->resource->getConnection()->select();
8396
$derivedTable->from(
84-
['main_table' => $this->tableResolver->getMainTable($currentScopeId)],
97+
['main_table' => $catalogCategoryProductTableName],
8598
[
8699
'value' => 'category_id'
87100
]

‎app/code/Magento/CatalogSearch/Model/Search/FilterMapper/ExclusionStrategy.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88

99
use Magento\CatalogSearch\Model\Adapter\Mysql\Filter\AliasResolver;
1010
use Magento\Framework\App\ObjectManager;
11-
use Magento\Catalog\Model\Indexer\Category\Product\TableResolver;
11+
use Magento\Framework\Indexer\ScopeResolver\IndexScopeResolver as TableResolver;
12+
use Magento\Framework\Search\Request\Dimension;
13+
use Magento\Catalog\Model\Indexer\Category\Product\AbstractAction;
1214

1315
/**
1416
* Strategy which processes exclusions from general rules
@@ -122,7 +124,18 @@ private function applyCategoryFilter(
122124
\Magento\Framework\DB\Select $select
123125
) {
124126
$alias = $this->aliasResolver->getAlias($filter);
125-
$tableName = $this->tableResolver->getMainTable($this->storeManager->getStore()->getId());
127+
128+
$catalogCategoryProductDimension = new Dimension(
129+
\Magento\Store\Model\Store::ENTITY,
130+
$this->storeManager->getStore()->getId()
131+
);
132+
133+
$tableName = $this->tableResolver->resolve(
134+
AbstractAction::MAIN_INDEX_TABLE,
135+
[
136+
$catalogCategoryProductDimension
137+
]
138+
);
126139
$mainTableAlias = $this->extractTableAliasFromSelect($select);
127140

128141
$select->joinInner(

0 commit comments

Comments
 (0)
Please sign in to comment.