Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2373 from magento-performance/MAGETWO-90413
[performance] MAGETWO-90413: Add plugin for backward compatibility in Category Product Indexer
- Loading branch information
Showing
6 changed files
with
97 additions
and
2 deletions.
There are no files selected for viewing
74 changes: 74 additions & 0 deletions
74
app/code/Magento/Catalog/Model/Indexer/Category/Product/Plugin/TableResolver.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
namespace Magento\Catalog\Model\Indexer\Category\Product\Plugin; | ||
|
||
use Magento\Framework\App\ResourceConnection; | ||
use Magento\Store\Model\StoreManagerInterface; | ||
use Magento\Framework\Indexer\ScopeResolver\IndexScopeResolver; | ||
use Magento\Catalog\Model\Indexer\Category\Product\AbstractAction; | ||
use Magento\Framework\Search\Request\Dimension; | ||
|
||
/** | ||
* Class that replace catalog_category_product_index table name on the table name segmented per store | ||
*/ | ||
class TableResolver | ||
{ | ||
/** | ||
* @var StoreManagerInterface | ||
*/ | ||
private $storeManager; | ||
|
||
/** | ||
* @var IndexScopeResolver | ||
*/ | ||
private $tableResolver; | ||
|
||
/** | ||
* @param StoreManagerInterface $storeManager | ||
* @param IndexScopeResolver $tableResolver | ||
*/ | ||
public function __construct( | ||
StoreManagerInterface $storeManager, | ||
IndexScopeResolver $tableResolver | ||
) { | ||
$this->storeManager = $storeManager; | ||
$this->tableResolver = $tableResolver; | ||
} | ||
|
||
/** | ||
* replacing catalog_category_product_index table name on the table name segmented per store | ||
* | ||
* @param ResourceConnection $subject | ||
* @param string $result | ||
* @param string|string[] $modelEntity | ||
* | ||
* @SuppressWarnings(PHPMD.UnusedFormalParameter) | ||
* | ||
* @return string | ||
*/ | ||
public function afterGetTableName( | ||
\Magento\Framework\App\ResourceConnection $subject, | ||
string $result, | ||
$modelEntity | ||
) { | ||
if (!is_array($modelEntity) && $modelEntity === AbstractAction::MAIN_INDEX_TABLE) { | ||
$catalogCategoryProductDimension = new Dimension( | ||
\Magento\Store\Model\Store::ENTITY, | ||
$this->storeManager->getStore()->getId() | ||
); | ||
|
||
$tableName = $this->tableResolver->resolve( | ||
AbstractAction::MAIN_INDEX_TABLE, | ||
[ | ||
$catalogCategoryProductDimension | ||
] | ||
); | ||
return $tableName; | ||
} | ||
return $result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters