Skip to content

Commit ed52dc9

Browse files
committed
Correct flat indexing with staging and > 500 cats.
Previously, the array was prefilled with entity_id values to ensure those categories were indexed. Unfortunately, when using row_id, it was using entity_ids. When chunking at 500, this could cause an overlapping row to be processed twice (the second time with missing non-static attributes), and cause a duplicate key error.
1 parent f1e6d1c commit ed52dc9

File tree

1 file changed

+31
-2
lines changed

1 file changed

+31
-2
lines changed

app/code/Magento/Catalog/Model/Indexer/Category/Flat/AbstractAction.php

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -369,9 +369,11 @@ protected function getAttributeValues($entityIds, $storeId)
369369
}
370370
$values = [];
371371

372-
foreach ($entityIds as $entityId) {
373-
$values[$entityId] = [];
372+
$linkIds = $this->getLinkIds($entityIds);
373+
foreach ($linkIds as $linkId) {
374+
$values[$linkId] = [];
374375
}
376+
375377
$attributes = $this->getAttributes();
376378
$attributesType = ['varchar', 'int', 'decimal', 'text', 'datetime'];
377379
foreach ($attributesType as $type) {
@@ -385,9 +387,36 @@ protected function getAttributeValues($entityIds, $storeId)
385387
}
386388
}
387389
}
390+
388391
return $values;
389392
}
390393

394+
/**
395+
* Translate entity ids into link ids
396+
*
397+
* Used for rows with no EAV attributes set.
398+
*
399+
* @param array $entityIds
400+
* @return array
401+
*/
402+
private function getLinkIds(array $entityIds)
403+
{
404+
$linkField = $this->getCategoryMetadata()->getLinkField();
405+
if ($linkField === 'entity_id') {
406+
return $entityIds;
407+
}
408+
409+
$select = $this->connection->select()->from(
410+
['e' => $this->connection->getTableName($this->getTableName('catalog_category_entity'))],
411+
[$linkField]
412+
)->where(
413+
'e.entity_id IN (?)',
414+
$entityIds
415+
);
416+
417+
return $this->connection->fetchCol($select);
418+
}
419+
391420
/**
392421
* Return attribute values for given entities and store of specific attribute type
393422
*

0 commit comments

Comments
 (0)