Skip to content

Commit 53d4c13

Browse files
committed
ACP2E-1028: Current Indexer implementation for large catalogs is causing items to not appear on site.
1 parent e365717 commit 53d4c13

File tree

2 files changed

+72
-6
lines changed

2 files changed

+72
-6
lines changed

app/code/Magento/Catalog/Model/Indexer/Product/Price/AbstractAction.php

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -387,13 +387,20 @@ protected function _reindexRows($changedIds = [])
387387
$changedIds = array_unique(array_merge($changedIds, ...array_values($parentProductsTypes)));
388388
$productsTypes = array_merge_recursive($productsTypes, $parentProductsTypes);
389389

390-
$typeIndexers = $this->getTypeIndexers();
391-
foreach ($typeIndexers as $productType => $indexer) {
392-
$entityIds = $productsTypes[$productType] ?? [];
393-
if (empty($entityIds)) {
394-
continue;
395-
}
390+
$typeIndexers = array_filter(
391+
$this->getTypeIndexers(),
392+
function ($type) use ($productsTypes) {
393+
return isset($productsTypes[$type]) && !empty($productsTypes[$type]);
394+
},
395+
ARRAY_FILTER_USE_KEY
396+
);
397+
if (empty($typeIndexers)) {
398+
$this->deleteIndexData($changedIds);
399+
return $changedIds;
400+
}
396401

402+
foreach ($typeIndexers as $productType => $indexer) {
403+
$entityIds = $productsTypes[$productType];
397404
if ($indexer instanceof DimensionalIndexerInterface) {
398405
foreach ($this->dimensionCollectionFactory->create() as $dimensions) {
399406
$this->tableMaintainer->createMainTmpTable($dimensions);

app/code/Magento/Catalog/Test/Unit/Model/Indexer/Product/Price/Action/RowsTest.php

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,4 +195,63 @@ public function testBatchProcessing()
195195

196196
$this->actionRows->execute($ids);
197197
}
198+
199+
public function testDeletedProductsBatchProcessing()
200+
{
201+
$ids = [1, 2, 3, 4];
202+
203+
$select = $this->createMock(Select::class);
204+
$select->method('from')->willReturnSelf();
205+
$select->method('joinLeft')->willReturnSelf();
206+
$select->method('where')->willReturnSelf();
207+
$select->method('join')->willReturnSelf();
208+
$adapter = $this->createMock(AdapterInterface::class);
209+
$adapter->method('select')->willReturn($select);
210+
$adapter->method('describeTable')->willReturn([]);
211+
$this->defaultIndexerResource->method('getConnection')->willReturn($adapter);
212+
$adapter->method('fetchAll')->with($select)->willReturn([]);
213+
214+
$adapter->expects($this->exactly(4))
215+
->method('fetchPairs')
216+
->with($select)
217+
->willReturnOnConsecutiveCalls([], [], [], []);
218+
$multiDimensionProvider = $this->createMock(MultiDimensionProvider::class);
219+
$this->dimensionCollectionFactory->expects($this->exactly(2))
220+
->method('create')
221+
->willReturn($multiDimensionProvider);
222+
$dimension = $this->createMock(Dimension::class);
223+
$dimension->method('getName')->willReturn('default');
224+
$dimension->method('getValue')->willReturn('0');
225+
$iterator = new \ArrayIterator([[$dimension]]);
226+
$multiDimensionProvider->expects($this->exactly(2))
227+
->method('getIterator')
228+
->willReturn($iterator);
229+
$this->catalogProductType->expects($this->once())
230+
->method('getTypesByPriority')
231+
->willReturn(
232+
[
233+
'virtual' => ['price_indexer' => '\Price\Indexer'],
234+
'simple' => ['price_indexer' => '\Price\Indexer'],
235+
]
236+
);
237+
$priceIndexer = $this->createMock(DimensionalIndexerInterface::class);
238+
$this->indexerPriceFactory->expects($this->exactly(2))
239+
->method('create')
240+
->with('\Price\Indexer', ['fullReindexAction' => false])
241+
->willReturn($priceIndexer);
242+
$priceIndexer->expects($this->never())
243+
->method('executeByDimensions');
244+
$select->expects($this->exactly(2))
245+
->method('deleteFromSelect')
246+
->with('index_price')
247+
->willReturn('');
248+
$adapter->expects($this->exactly(2))
249+
->method('getIndexList')
250+
->willReturn(['entity_id'=>['COLUMNS_LIST'=>['test']]]);
251+
$adapter->expects($this->exactly(2))
252+
->method('getPrimaryKeyName')
253+
->willReturn('entity_id');
254+
255+
$this->actionRows->execute($ids);
256+
}
198257
}

0 commit comments

Comments
 (0)