Skip to content

Commit 9f78c28

Browse files
committed
MAGETWO-92819: Optimize moveDataFromReplicaTableToReplicaTables
1 parent 8c8a626 commit 9f78c28

File tree

1 file changed

+10
-2
lines changed
  • app/code/Magento/Catalog/Model/Indexer/Product/Price/Action

1 file changed

+10
-2
lines changed

app/code/Magento/Catalog/Model/Indexer/Product/Price/Action/Full.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -415,11 +415,17 @@ private function moveDataFromReplicaTableToReplicaTables(array $dimensions)
415415
if (!$dimensions) {
416416
return ;
417417
}
418-
//TODO: need to update logic for run this move only when replica table is not empty
419418
$select = $this->dimensionTableMaintainer->getConnection()->select()->from(
420-
$this->dimensionTableMaintainer->getMainReplicaTable([])
419+
$mainReplicaTable = $this->dimensionTableMaintainer->getMainReplicaTable([])
421420
);
422421

422+
$check = clone $select;
423+
$check->reset('columns')->columns('count(*)');
424+
425+
if (! $count = $this->dimensionTableMaintainer->getConnection()->query($check)->fetchColumn()) {
426+
return;
427+
}
428+
423429
$replicaTablesByDimension = $this->dimensionTableMaintainer->getMainReplicaTable($dimensions);
424430

425431
foreach ($dimensions as $dimension) {
@@ -439,6 +445,8 @@ private function moveDataFromReplicaTableToReplicaTables(array $dimensions)
439445
\Magento\Framework\DB\Adapter\AdapterInterface::INSERT_ON_DUPLICATE
440446
)
441447
);
448+
449+
$this->_defaultIndexerResource->getConnection()->truncateTable($mainReplicaTable);
442450
}
443451

444452
/**

0 commit comments

Comments
 (0)