Skip to content

Commit

Permalink
Merge pull request #2373 from magento-performance/MAGETWO-90413
Browse files Browse the repository at this point in the history
[performance] MAGETWO-90413: Add plugin for backward compatibility in Category Product Indexer
  • Loading branch information
Oleksii Korshenko committed Apr 13, 2018
2 parents 565edc9 + eda56e9 commit f378f1f
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 2 deletions.
@@ -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;
}
}
Expand Up @@ -136,10 +136,19 @@ public function getMainTable(int $storeId)
public function createTablesForStore(int $storeId)
{
$mainTableName = $this->getMainTable($storeId);
$this->createTable($this->getTable(AbstractAction::MAIN_INDEX_TABLE), $mainTableName);
//Create index table for store based on on main replica table
//Using main replica table is necessary for backward capability and TableResolver plugin work
$this->createTable(
$this->getTable(AbstractAction::MAIN_INDEX_TABLE . $this->additionalTableSuffix),
$mainTableName
);

$mainReplicaTableName = $this->getMainTable($storeId) . $this->additionalTableSuffix;
$this->createTable($this->getTable(AbstractAction::MAIN_INDEX_TABLE), $mainReplicaTableName);
//Create replica table for store based on main replica table
$this->createTable(
$this->getTable(AbstractAction::MAIN_INDEX_TABLE . $this->additionalTableSuffix),
$mainReplicaTableName
);
}

/**
Expand Down
3 changes: 3 additions & 0 deletions app/code/Magento/Catalog/etc/adminhtml/di.xml
Expand Up @@ -193,4 +193,7 @@
<type name="Magento\Eav\Api\AttributeSetRepositoryInterface">
<plugin name="remove_products" type="Magento\Catalog\Plugin\Model\AttributeSetRepository\RemoveProducts"/>
</type>
<type name="Magento\Framework\App\ResourceConnection">
<plugin name="get_catalog_category_product_index_table_name" type="Magento\Catalog\Model\Indexer\Category\Product\Plugin\TableResolver"/>
</type>
</config>
3 changes: 3 additions & 0 deletions app/code/Magento/Catalog/etc/frontend/di.xml
Expand Up @@ -79,4 +79,7 @@
<argument name="typeId" xsi:type="string">recently_compared_product</argument>
</arguments>
</virtualType>
<type name="Magento\Framework\App\ResourceConnection">
<plugin name="get_catalog_category_product_index_table_name" type="Magento\Catalog\Model\Indexer\Category\Product\Plugin\TableResolver"/>
</type>
</config>
3 changes: 3 additions & 0 deletions app/code/Magento/Catalog/etc/webapi_rest/di.xml
Expand Up @@ -16,4 +16,7 @@
</argument>
</arguments>
</type>
<type name="Magento\Framework\App\ResourceConnection">
<plugin name="get_catalog_category_product_index_table_name" type="Magento\Catalog\Model\Indexer\Category\Product\Plugin\TableResolver"/>
</type>
</config>
3 changes: 3 additions & 0 deletions app/code/Magento/Catalog/etc/webapi_soap/di.xml
Expand Up @@ -15,4 +15,7 @@
</argument>
</arguments>
</type>
<type name="Magento\Framework\App\ResourceConnection">
<plugin name="get_catalog_category_product_index_table_name" type="Magento\Catalog\Model\Indexer\Category\Product\Plugin\TableResolver"/>
</type>
</config>

0 comments on commit f378f1f

Please sign in to comment.