Skip to content

Commit e69871c

Browse files
Valeriy Naydavzabaznov
authored andcommitted
MAGETWO-66401: [Backport] - [Performance] Bump in stock SQL queries - for 2.1.6
- MAGETWO-66344: [Performance] Bump in stock SQL queries -- (cherry picked from commit 8fa0fb0)
1 parent 506a93f commit e69871c

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

app/code/Magento/ConfigurableProduct/Pricing/Price/LowestPriceOptionsProvider.php

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@ class LowestPriceOptionsProvider implements LowestPriceOptionsProviderInterface
3030
*/
3131
private $collectionFactory;
3232

33+
/**
34+
* Key is product id. Value is prepared product collection
35+
*
36+
* @var array
37+
*/
38+
private $productsMap;
39+
3340
/**
3441
* @param ResourceConnection $resourceConnection
3542
* @param LinkedProductSelectBuilderInterface $linkedProductSelectBuilder
@@ -50,14 +57,16 @@ public function __construct(
5057
*/
5158
public function getProducts(ProductInterface $product)
5259
{
53-
$productIds = $this->resource->getConnection()->fetchCol(
54-
'(' . implode(') UNION (', $this->linkedProductSelectBuilder->build($product->getId())) . ')'
55-
);
56-
57-
$lowestPriceChildProducts = $this->collectionFactory->create()
58-
->addAttributeToSelect(['price', 'special_price'])
59-
->addIdFilter($productIds)
60-
->getItems();
61-
return $lowestPriceChildProducts;
60+
if (!isset($this->productsMap[$product->getId()])) {
61+
$productIds = $this->resource->getConnection()->fetchCol(
62+
'(' . implode(') UNION (', $this->linkedProductSelectBuilder->build($product->getId())) . ')'
63+
);
64+
65+
$this->productsMap[$product->getId()] = $this->collectionFactory->create()
66+
->addAttributeToSelect(['price', 'special_price'])
67+
->addIdFilter($productIds)
68+
->getItems();
69+
}
70+
return $this->productsMap[$product->getId()];
6271
}
6372
}

0 commit comments

Comments
 (0)