Skip to content

Commit 2b022a7

Browse files
committed
MAGETWO-90041: Changing the code structure for segmentation for Category Product Indexer
1 parent 3860250 commit 2b022a7

File tree

7 files changed

+44
-65
lines changed

7 files changed

+44
-65
lines changed

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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

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

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

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

910
use Magento\Framework\App\ResourceConnection;
1011
use Magento\Framework\Search\Request\Dimension;
1112
use Magento\Framework\DB\Adapter\AdapterInterface;
13+
use Magento\Catalog\Model\Indexer\Category\Product\AbstractAction;
14+
use Magento\Framework\Indexer\ScopeResolver\IndexScopeResolver as TableResolver;
1215

1316
class TableMaintainer
1417
{
@@ -52,7 +55,19 @@ public function __construct(
5255
) {
5356
$this->resource = $resource;
5457
$this->tableResolver = $tableResolver;
55-
$this->connection = $resource->getConnection();
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,8 +107,8 @@ 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

@@ -108,7 +123,7 @@ public function getMainTable(int $storeId)
108123
{
109124
$catalogCategoryProductDimension = new Dimension(\Magento\Store\Model\Store::ENTITY, $storeId);
110125

111-
return $this->tableResolver->resolve(TableResolver::MAIN_INDEX_TABLE, [$catalogCategoryProductDimension]);
126+
return $this->tableResolver->resolve(AbstractAction::MAIN_INDEX_TABLE, [$catalogCategoryProductDimension]);
112127
}
113128

114129
/**
@@ -121,10 +136,10 @@ public function getMainTable(int $storeId)
121136
public function createTablesForStore(int $storeId)
122137
{
123138
$mainTableName = $this->getMainTable($storeId);
124-
$this->createTable($this->getTable(TableResolver::MAIN_INDEX_TABLE), $mainTableName);
139+
$this->createTable($this->getTable(AbstractAction::MAIN_INDEX_TABLE), $mainTableName);
125140

126141
$mainReplicaTableName = $this->getMainTable($storeId) . $this->additionalTableSuffix;
127-
$this->createTable($this->getTable(TableResolver::MAIN_INDEX_TABLE), $mainReplicaTableName);
142+
$this->createTable($this->getTable(AbstractAction::MAIN_INDEX_TABLE), $mainReplicaTableName);
128143
}
129144

130145
/**
@@ -167,7 +182,7 @@ public function createMainTmpTable(int $storeId)
167182
if (!isset($this->mainTmpTable[$storeId])) {
168183
$originTableName = $this->getMainTable($storeId);
169184
$temporaryTableName = $this->getMainTable($storeId) . $this->tmpTableSuffix;
170-
$this->connection->createTemporaryTableLike($temporaryTableName, $originTableName, true);
185+
$this->getConnection()->createTemporaryTableLike($temporaryTableName, $originTableName, true);
171186
$this->mainTmpTable[$storeId] = $temporaryTableName;
172187
}
173188
}

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

Lines changed: 0 additions & 47 deletions
This file was deleted.

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/CatalogSearch/Model/Adapter/Mysql/Plugin/Aggregation/Category/DataProvider.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
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

1819
class DataProvider
1920
{
@@ -83,7 +84,7 @@ public function aroundGetDataSet(
8384
$catalogCategoryProductDimension = new Dimension(\Magento\Store\Model\Store::ENTITY, $currentScopeId);
8485

8586
$catalogCategoryProductTableName = $this->tableResolver->resolve(
86-
TableResolver::MAIN_INDEX_TABLE,
87+
AbstractAction::MAIN_INDEX_TABLE,
8788
[
8889
$catalogCategoryProductDimension
8990
]

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +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;
1212
use Magento\Framework\Search\Request\Dimension;
13+
use Magento\Catalog\Model\Indexer\Category\Product\AbstractAction;
1314

1415
/**
1516
* Strategy which processes exclusions from general rules
@@ -131,7 +132,7 @@ private function applyCategoryFilter(
131132
);
132133

133134
$tableName = $this->tableResolver->resolve(
134-
TableResolver::MAIN_INDEX_TABLE,
135+
AbstractAction::MAIN_INDEX_TABLE,
135136
[
136137
$catalogCategoryProductDimension
137138
]

0 commit comments

Comments
 (0)