Skip to content

Commit fa66aa7

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

File tree

2 files changed

+56
-1
lines changed

2 files changed

+56
-1
lines changed

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

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

88
use Magento\Catalog\Api\Data\ProductInterface;
9+
use Magento\Framework\App\ObjectManager;
910

1011
/**
1112
* Catalog Product Eav Attributes abstract indexer resource model
@@ -54,6 +55,7 @@ public function reindexAll()
5455
$this->clearTemporaryIndexTable();
5556
$this->_prepareIndex();
5657
$this->_prepareRelationIndex();
58+
$this->_removeNotVisibleEntityFromIndex();
5759
$this->syncData();
5860
$this->commit();
5961
} catch (\Exception $e) {
@@ -76,6 +78,7 @@ public function reindexEntities($processIds)
7678

7779
$this->_prepareIndex($processIds);
7880
$this->_prepareRelationIndex($processIds);
81+
$this->_removeNotVisibleEntityFromIndex();
7982

8083
return $this;
8184
}
@@ -88,7 +91,6 @@ public function reindexEntities($processIds)
8891
* @param int $attributeId
8992
* @param bool $isIndexable
9093
* @return $this
91-
* @throws \Exception
9294
*/
9395
public function reindexAttribute($attributeId, $isIndexable = true)
9496
{
@@ -99,6 +101,7 @@ public function reindexAttribute($attributeId, $isIndexable = true)
99101

100102
$this->_prepareIndex(null, $attributeId);
101103
$this->_prepareRelationIndex();
104+
$this->_removeNotVisibleEntityFromIndex();
102105

103106
$this->_synchronizeAttributeIndexData($attributeId);
104107
}
@@ -115,6 +118,39 @@ public function reindexAttribute($attributeId, $isIndexable = true)
115118
*/
116119
abstract protected function _prepareIndex($entityIds = null, $attributeId = null);
117120

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+
118154
/**
119155
* Prepare data index select for product relations
120156
*

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,25 @@ public function __construct(
7575
->get(\Magento\Framework\Api\SearchCriteriaBuilder::class);
7676
}
7777

78+
/**
79+
* @inheritDoc
80+
*/
81+
public function reindexAttribute($attributeId, $isIndexable = true)
82+
{
83+
if (!$isIndexable) {
84+
$this->_removeAttributeIndexData($attributeId);
85+
} else {
86+
$this->clearTemporaryIndexTable();
87+
88+
$this->_prepareIndex(null, $attributeId);
89+
$this->_prepareRelationIndex();
90+
91+
$this->_synchronizeAttributeIndexData($attributeId);
92+
}
93+
94+
return $this;
95+
}
96+
7897
/**
7998
* Initialize connection and define main index table
8099
*

0 commit comments

Comments
 (0)