Skip to content

Commit df4d868

Browse files
committed
ACP2E-2222: EAV Indexer performance
- implemented solution
1 parent 0a834cc commit df4d868

File tree

2 files changed

+30
-40
lines changed

2 files changed

+30
-40
lines changed

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

Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
namespace Magento\Catalog\Model\ResourceModel\Product\Indexer\Eav;
77

88
use Magento\Catalog\Api\Data\ProductInterface;
9-
use Magento\Framework\App\ObjectManager;
109

1110
/**
1211
* Catalog Product Eav Attributes abstract indexer resource model
@@ -55,7 +54,6 @@ public function reindexAll()
5554
$this->clearTemporaryIndexTable();
5655
$this->_prepareIndex();
5756
$this->_prepareRelationIndex();
58-
$this->_removeNotVisibleEntityFromIndex();
5957
$this->syncData();
6058
$this->commit();
6159
} catch (\Exception $e) {
@@ -78,7 +76,6 @@ public function reindexEntities($processIds)
7876

7977
$this->_prepareIndex($processIds);
8078
$this->_prepareRelationIndex($processIds);
81-
$this->_removeNotVisibleEntityFromIndex();
8279

8380
return $this;
8481
}
@@ -91,6 +88,7 @@ public function reindexEntities($processIds)
9188
* @param int $attributeId
9289
* @param bool $isIndexable
9390
* @return $this
91+
* @throws \Exception
9492
*/
9593
public function reindexAttribute($attributeId, $isIndexable = true)
9694
{
@@ -101,7 +99,6 @@ public function reindexAttribute($attributeId, $isIndexable = true)
10199

102100
$this->_prepareIndex(null, $attributeId);
103101
$this->_prepareRelationIndex();
104-
$this->_removeNotVisibleEntityFromIndex();
105102

106103
$this->_synchronizeAttributeIndexData($attributeId);
107104
}
@@ -118,39 +115,6 @@ public function reindexAttribute($attributeId, $isIndexable = true)
118115
*/
119116
abstract protected function _prepareIndex($entityIds = null, $attributeId = null);
120117

121-
/**
122-
* Remove Not Visible products from temporary data index
123-
*
124-
* @return $this
125-
*/
126-
protected function _removeNotVisibleEntityFromIndex()
127-
{
128-
$connection = $this->getConnection();
129-
$idxTable = $this->getIdxTable();
130-
131-
$select = $connection->select()->from($idxTable, null);
132-
133-
$select->joinLeft(
134-
['cpe' => $this->getTable('catalog_product_entity')],
135-
"cpe.entity_id = {$idxTable}.entity_id",
136-
[]
137-
);
138-
$linkField = $this->getMetadataPool()->getMetadata(ProductInterface::class)->getLinkField();
139-
$condition = $connection->quoteInto('=?', \Magento\Catalog\Model\Product\Visibility::VISIBILITY_NOT_VISIBLE);
140-
$this->_addAttributeToSelect(
141-
$select,
142-
'visibility',
143-
"cpe.{$linkField}",
144-
$idxTable . '.store_id',
145-
$condition
146-
);
147-
148-
$query = $select->deleteFromSelect($idxTable);
149-
$connection->query($query);
150-
151-
return $this;
152-
}
153-
154118
/**
155119
* Prepare data index select for product relations
156120
*

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

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ protected function _prepareIndex($entityIds = null, $attributeId = null)
135135
* @param int $attributeId the attribute id limitation
136136
* @return $this
137137
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
138+
* @throws \Exception
138139
*/
139140
protected function _prepareSelectIndex($entityIds = null, $attributeId = null)
140141
{
@@ -149,7 +150,7 @@ protected function _prepareSelectIndex($entityIds = null, $attributeId = null)
149150
$attrIdsFlat = implode(',', array_map('intval', $attrIds));
150151
$ifNullSql = $connection->getIfNullSql('pis.value', 'COALESCE(ds.value, dd.value)');
151152

152-
/**@var $select \Magento\Framework\DB\Select*/
153+
/**@var $select Select */
153154
$select = $connection->select()->distinct(true)->from(
154155
['s' => $this->getTable('store')],
155156
[]
@@ -204,6 +205,15 @@ protected function _prepareSelectIndex($entityIds = null, $attributeId = null)
204205
'cpe.entity_id AS source_id',
205206
]
206207
);
208+
$visibilityCondition = $connection->quoteInto('>?', \Magento\Catalog\Model\Product\Visibility::VISIBILITY_NOT_VISIBLE);
209+
$linkField = $this->getMetadataPool()->getMetadata(ProductInterface::class)->getLinkField();
210+
$this->_addAttributeToSelect(
211+
$select,
212+
'visibility',
213+
"cpe.{$linkField}",
214+
'pis.store_id',
215+
$visibilityCondition
216+
);
207217

208218
if ($entityIds !== null) {
209219
$ids = implode(',', array_map('intval', $entityIds));
@@ -239,6 +249,14 @@ protected function _prepareSelectIndex($entityIds = null, $attributeId = null)
239249
->where('wd.store_id != 0')
240250
->where("cpe.entity_id IN({$ids})");
241251
$select->where("cpe.entity_id IN({$ids})");
252+
$this->_addAttributeToSelect(
253+
$selectWithoutDefaultStore,
254+
'visibility',
255+
"cpe.{$linkField}",
256+
'd2s.store_id',
257+
$visibilityCondition
258+
);
259+
242260
$selects = new UnionExpression(
243261
[$select, $selectWithoutDefaultStore],
244262
Select::SQL_UNION,
@@ -272,6 +290,7 @@ protected function _prepareSelectIndex($entityIds = null, $attributeId = null)
272290
* @param array $entityIds the entity ids limitation
273291
* @param int $attributeId the attribute id limitation
274292
* @return $this
293+
* @throws \Exception
275294
*/
276295
protected function _prepareMultiselectIndex($entityIds = null, $attributeId = null)
277296
{
@@ -358,6 +377,13 @@ protected function _prepareMultiselectIndex($entityIds = null, $attributeId = nu
358377
]
359378
);
360379

380+
$this->_addAttributeToSelect(
381+
$select,
382+
'visibility',
383+
"cpe.{$productIdField}",
384+
'cs.store_id',
385+
$connection->quoteInto('>?', \Magento\Catalog\Model\Product\Visibility::VISIBILITY_NOT_VISIBLE)
386+
);
361387
$this->saveDataFromSelect($select, $options);
362388

363389
return $this;
@@ -431,11 +457,11 @@ public function getIdxTable($table = null)
431457
/**
432458
* Save data from select
433459
*
434-
* @param \Magento\Framework\DB\Select $select
460+
* @param Select $select
435461
* @param array $options
436462
* @return void
437463
*/
438-
private function saveDataFromSelect(\Magento\Framework\DB\Select $select, array $options)
464+
private function saveDataFromSelect(Select $select, array $options)
439465
{
440466
$i = 0;
441467
$data = [];

0 commit comments

Comments
 (0)