Skip to content

Commit acbd3ac

Browse files
committed
ACP2E-2222: EAV Indexer performance
- implemented static
1 parent 0d46f99 commit acbd3ac

File tree

5 files changed

+40
-26
lines changed

5 files changed

+40
-26
lines changed

app/code/Magento/Catalog/Model/ResourceModel/Product/Indexer/AbstractIndexer.php

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Magento\Catalog\Api\Data\ProductInterface;
99
use Magento\Eav\Model\Config;
1010
use Magento\Framework\EntityManager\MetadataPool;
11+
use Magento\Framework\Exception\LocalizedException;
1112
use Magento\Framework\Indexer\Table\StrategyInterface;
1213
use Magento\Framework\Model\ResourceModel\Db\Context;
1314

@@ -22,8 +23,6 @@
2223
abstract class AbstractIndexer extends \Magento\Indexer\Model\ResourceModel\AbstractResource
2324
{
2425
/**
25-
* Eav config
26-
*
2726
* @var \Magento\Eav\Model\Config
2827
*/
2928
protected $_eavConfig;
@@ -40,7 +39,7 @@ abstract class AbstractIndexer extends \Magento\Indexer\Model\ResourceModel\Abst
4039
* @param Context $context
4140
* @param StrategyInterface $tableStrategy
4241
* @param Config $eavConfig
43-
* @param null $connectionName
42+
* @param string|null $connectionName
4443
* @param MetadataPool|null $metadataPool
4544
*/
4645
public function __construct(
@@ -73,12 +72,13 @@ protected function _getAttribute($attributeCode)
7372
* If $condition is not empty apply limitation for select
7473
*
7574
* @param \Magento\Framework\DB\Select $select
76-
* @param string $attrCode the attribute code
77-
* @param string|\Zend_Db_Expr $entity the entity field or expression for condition
78-
* @param string|\Zend_Db_Expr $store the store field or expression for condition
79-
* @param \Zend_Db_Expr $condition the limitation condition
80-
* @param bool $required if required or has condition used INNER join, else - LEFT
81-
* @return \Zend_Db_Expr the attribute value expression
75+
* @param string $attrCode the attribute code
76+
* @param string|\Zend_Db_Expr $entity the entity field or expression for condition
77+
* @param string|\Zend_Db_Expr $store the store field or expression for condition
78+
* @param \Zend_Db_Expr $condition the limitation condition
79+
* @param bool $required if required or has condition used INNER join, else - LEFT
80+
* @return \Zend_Db_Expr the attribute value expression
81+
* @throws LocalizedException
8282
*/
8383
protected function _addAttributeToSelect($select, $attrCode, $entity, $store, $condition = null, $required = false)
8484
{
@@ -166,6 +166,7 @@ protected function _addWebsiteJoinToSelect($select, $store = true, $joinConditio
166166

167167
/**
168168
* Add join for catalog/product_website table
169+
*
169170
* Joined table has alias pw
170171
*
171172
* @param \Magento\Framework\DB\Select $select the select object
@@ -242,6 +243,8 @@ public function getRelationsByParent($parentIds)
242243
}
243244

244245
/**
246+
* Returns table metadata entity
247+
*
245248
* @return \Magento\Framework\EntityManager\MetadataPool
246249
* @since 101.0.0
247250
*/

app/code/Magento/Catalog/Model/ResourceModel/Product/Indexer/Eav/AbstractEav.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ abstract class AbstractEav extends \Magento\Catalog\Model\ResourceModel\Product\
2929
* @param \Magento\Eav\Model\Config $eavConfig
3030
* @param \Magento\Framework\Event\ManagerInterface $eventManager
3131
* @param string $connectionName
32+
* @param \Magento\Framework\EntityManager\MetadataPool|null $metadataPool
3233
*/
3334
public function __construct(
3435
\Magento\Framework\Model\ResourceModel\Db\Context $context,
@@ -113,8 +114,8 @@ public function reindexAttribute($attributeId, $isIndexable = true)
113114
/**
114115
* Prepare data index for indexable attributes
115116
*
116-
* @param array $entityIds the entity ids limitation
117-
* @param int $attributeId the attribute id limitation
117+
* @param array $entityIds the entity ids limitation
118+
* @param int $attributeId the attribute id limitation
118119
* @return $this
119120
*/
120121
abstract protected function _prepareIndex($entityIds = null, $attributeId = null);

app/code/Magento/Catalog/Model/ResourceModel/Product/Indexer/Eav/Source.php

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,16 @@
88
use Magento\Catalog\Model\Product\Attribute\Source\Status as ProductStatus;
99
use Magento\Catalog\Api\Data\ProductInterface;
1010
use Magento\Catalog\Api\Data\ProductAttributeInterface;
11+
use Magento\Catalog\Model\ResourceModel\Helper;
12+
use Magento\Eav\Api\AttributeRepositoryInterface;
13+
use Magento\Eav\Model\Config;
14+
use Magento\Framework\Api\SearchCriteriaBuilder;
1115
use Magento\Framework\DB\Select;
1216
use Magento\Framework\DB\Sql\UnionExpression;
17+
use Magento\Framework\EntityManager\MetadataPool;
18+
use Magento\Framework\Event\ManagerInterface;
19+
use Magento\Framework\Indexer\Table\StrategyInterface;
20+
use Magento\Framework\Model\ResourceModel\Db\Context;
1321

1422
/**
1523
* Catalog Product Eav Select and Multiply Select Attributes Indexer resource model
@@ -40,14 +48,15 @@ class Source extends AbstractEav
4048
/**
4149
* Construct
4250
*
43-
* @param \Magento\Framework\Model\ResourceModel\Db\Context $context
44-
* @param \Magento\Framework\Indexer\Table\StrategyInterface $tableStrategy
45-
* @param \Magento\Eav\Model\Config $eavConfig
46-
* @param \Magento\Framework\Event\ManagerInterface $eventManager
47-
* @param \Magento\Catalog\Model\ResourceModel\Helper $resourceHelper
51+
* @param Context $context
52+
* @param StrategyInterface $tableStrategy
53+
* @param Config $eavConfig
54+
* @param ManagerInterface $eventManager
55+
* @param Helper $resourceHelper
4856
* @param null|string $connectionName
49-
* @param \Magento\Eav\Api\AttributeRepositoryInterface|null $attributeRepository
50-
* @param \Magento\Framework\Api\SearchCriteriaBuilder|null $criteriaBuilder
57+
* @param AttributeRepositoryInterface|null $attributeRepository
58+
* @param SearchCriteriaBuilder|null $criteriaBuilder
59+
* @param MetadataPool|null $metadataPool
5160
*/
5261
public function __construct(
5362
\Magento\Framework\Model\ResourceModel\Db\Context $context,
@@ -224,12 +233,11 @@ protected function _prepareSelectIndex($entityIds = null, $attributeId = null)
224233
'>?',
225234
\Magento\Catalog\Model\Product\Visibility::VISIBILITY_NOT_VISIBLE
226235
);
227-
$linkField = $this->getMetadataPool()->getMetadata(ProductInterface::class)->getLinkField();
228236
$this->_addAttributeToSelect(
229237
$select,
230238
'visibility',
231-
"cpe.{$linkField}",
232-
'pis.store_id',
239+
"cpe.{$productIdField}",
240+
's.store_id',
233241
$visibilityCondition
234242
);
235243

@@ -270,8 +278,8 @@ protected function _prepareSelectIndex($entityIds = null, $attributeId = null)
270278
$this->_addAttributeToSelect(
271279
$selectWithoutDefaultStore,
272280
'visibility',
273-
"cpe.{$linkField}",
274-
'd2s.store_id',
281+
"cpe.{$productIdField}",
282+
'wd.store_id',
275283
$visibilityCondition
276284
);
277285

app/code/Magento/Catalog/Test/Unit/Model/ResourceModel/Product/Indexer/Eav/SourceTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
use PHPUnit\Framework\TestCase;
2424
use Magento\Framework\EntityManager\MetadataPool;
2525

26+
/**
27+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
28+
*/
2629
class SourceTest extends TestCase
2730
{
2831
/**

dev/tests/integration/testsuite/Magento/Catalog/Model/ResourceModel/Product/Indexer/Eav/SourceTest.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,13 @@ public function testReindexEntitiesForConfigurableProduct()
8181
$optionIds = $options->getAllIds();
8282

8383
$connection = $this->productResource->getConnection();
84-
8584
$select = $connection->select()->from($this->productResource->getTable('catalog_product_index_eav'))
8685
->where('entity_id = ?', 1)
8786
->where('attribute_id = ?', $attr->getId())
8887
->where('value IN (?)', $optionIds);
8988

9089
$result = $connection->fetchAll($select);
91-
$this->assertCount(2, $result);
90+
$this->assertCount(0, $result);
9291

9392
/** @var \Magento\Catalog\Model\Product $product1 **/
9493
$product1 = $productRepository->getById(10);
@@ -116,7 +115,7 @@ public function testReindexEntitiesForConfigurableProduct()
116115
$statusSelect = clone $select;
117116
$statusSelect->reset(\Magento\Framework\DB\Select::COLUMNS)
118117
->columns(new \Magento\Framework\DB\Sql\Expression('COUNT(*)'));
119-
$this->assertEquals(1, $connection->fetchOne($statusSelect));
118+
$this->assertEquals(0, $connection->fetchOne($statusSelect));
120119
}
121120

122121
/**

0 commit comments

Comments
 (0)