Skip to content

Commit 9af3b12

Browse files
committed
MC-23215: Slow catalog_product_price indexer for Bundle products
1 parent 9dbaaad commit 9af3b12

File tree

1 file changed

+28
-15
lines changed
  • app/code/Magento/Bundle/Model/ResourceModel/Indexer

1 file changed

+28
-15
lines changed

app/code/Magento/Bundle/Model/ResourceModel/Indexer/Price.php

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -458,17 +458,17 @@ private function getBaseBundleSelectionPriceSelect(): Select
458458
}
459459

460460
/**
461-
* Calculate product selections price for fixed bundles
461+
* Apply selections price for fixed bundles
462462
*
463463
* @return void
464464
* @throws \Exception
465465
*/
466-
private function calculateFixedBundleSelectionPrice()
466+
private function applyFixedBundleSelectionPrice()
467467
{
468468
$connection = $this->getConnection();
469469

470-
$selectionPriceValue = 'bs.selection_price_value';
471-
$selectionPriceType = 'bs.selection_price_type';
470+
$selectionPriceValue = 'bsp.selection_price_value';
471+
$selectionPriceType = 'bsp.selection_price_type';
472472
$priceExpr = new \Zend_Db_Expr(
473473
$connection->getCheckSql(
474474
$selectionPriceType . ' = 1',
@@ -501,7 +501,11 @@ private function calculateFixedBundleSelectionPrice()
501501
);
502502

503503
$select = $this->getBaseBundleSelectionPriceSelect();
504-
$select->where(
504+
$select->joinInner(
505+
['bsp' => $this->getTable('catalog_product_bundle_selection_price')],
506+
'bs.selection_id = bsp.selection_id AND bsp.website_id = i.website_id',
507+
[]
508+
)->where(
505509
'i.price_type=?',
506510
\Magento\Bundle\Model\Product\Price::PRICE_TYPE_FIXED
507511
)->columns(
@@ -512,11 +516,22 @@ private function calculateFixedBundleSelectionPrice()
512516
'tier_price' => $tierExpr,
513517
]
514518
);
515-
$query = $select->insertFromSelect($this->getBundleSelectionTable());
519+
$query = $select->crossUpdateFromSelect($this->getBundleSelectionTable());
516520
$connection->query($query);
521+
}
517522

518-
$selectionPriceValue = 'bsp.selection_price_value';
519-
$selectionPriceType = 'bsp.selection_price_type';
523+
/**
524+
* Calculate selections price for fixed bundles
525+
*
526+
* @return void
527+
* @throws \Exception
528+
*/
529+
private function calculateFixedBundleSelectionPrice()
530+
{
531+
$connection = $this->getConnection();
532+
533+
$selectionPriceValue = 'bs.selection_price_value';
534+
$selectionPriceType = 'bs.selection_price_type';
520535
$priceExpr = new \Zend_Db_Expr(
521536
$connection->getCheckSql(
522537
$selectionPriceType . ' = 1',
@@ -549,11 +564,7 @@ private function calculateFixedBundleSelectionPrice()
549564
);
550565

551566
$select = $this->getBaseBundleSelectionPriceSelect();
552-
$select->joinInner(
553-
['bsp' => $this->getTable('catalog_product_bundle_selection_price')],
554-
'bs.selection_id = bsp.selection_id AND bsp.website_id = i.website_id',
555-
[]
556-
)->where(
567+
$select->where(
557568
'i.price_type=?',
558569
\Magento\Bundle\Model\Product\Price::PRICE_TYPE_FIXED
559570
)->columns(
@@ -564,12 +575,14 @@ private function calculateFixedBundleSelectionPrice()
564575
'tier_price' => $tierExpr,
565576
]
566577
);
567-
$query = $select->crossUpdateFromSelect($this->getBundleSelectionTable());
578+
$query = $select->insertFromSelect($this->getBundleSelectionTable());
568579
$connection->query($query);
580+
581+
$this->applyFixedBundleSelectionPrice();
569582
}
570583

571584
/**
572-
* Calculate product selections price for dynamic bundles
585+
* Calculate selections price for dynamic bundles
573586
*
574587
* @param array $dimensions
575588
* @return void

0 commit comments

Comments
 (0)