Skip to content

Commit 4cf3c38

Browse files
author
Yaroslav Onischenko
committed
MAGETWO-66515: [Performance] Reduce queries to stock_status_index on Category Page
1 parent 18874e8 commit 4cf3c38

File tree

2 files changed

+17
-17
lines changed

2 files changed

+17
-17
lines changed

app/code/Magento/ConfigurableProduct/Model/Product/Type/Configurable.php

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1270,15 +1270,13 @@ public function getSalableUsedProducts(\Magento\Catalog\Model\Product $product,
12701270
* @param \Magento\Catalog\Model\Product $product
12711271
* @param string $cacheKey
12721272
* @param bool $salableOnly
1273-
* @return ProductInterface[]|null
1273+
* @return ProductInterface[]
12741274
*/
12751275
private function loadUsedProducts(\Magento\Catalog\Model\Product $product, $cacheKey, $salableOnly = false)
12761276
{
1277-
\Magento\Framework\Profiler::start(
1278-
'CONFIGURABLE:' . __METHOD__,
1279-
['group' => 'CONFIGURABLE', 'method' => __METHOD__]
1280-
);
1281-
if (!$product->hasData($this->usedSalableProducts)) {
1277+
$dataFieldName = $salableOnly ? $this->usedSalableProducts : $this->_usedProducts;
1278+
$hasData = $product->hasData($dataFieldName);
1279+
if (!$hasData) {
12821280
$usedProducts = $this->readUsedProductsCacheData($cacheKey);
12831281
if ($usedProducts === null) {
12841282
$collection = $this->getConfiguredUsedProductCollection($product);
@@ -1288,11 +1286,11 @@ private function loadUsedProducts(\Magento\Catalog\Model\Product $product, $cach
12881286
$usedProducts = $collection->getItems();
12891287
$this->saveUsedProductsCacheData($product, $usedProducts, $cacheKey);
12901288
}
1291-
$product->setData($this->usedSalableProducts, $usedProducts);
1289+
$product->setData($dataFieldName, $usedProducts);
12921290
}
1293-
\Magento\Framework\Profiler::stop('CONFIGURABLE:' . __METHOD__);
1291+
$child = $product->getData($dataFieldName);
12941292

1295-
return $product->getData($this->usedSalableProducts);
1293+
return $child;
12961294
}
12971295

12981296
/**

app/code/Magento/ConfigurableProduct/Test/Unit/Model/Product/Type/ConfigurableTest.php

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -822,18 +822,20 @@ public function testSetImageFromChildProduct()
822822
$childProductMock = $this->getMockBuilder(\Magento\Catalog\Model\Product::class)
823823
->disableOriginalConstructor()
824824
->getMock();
825+
$this->entityMetadata->expects($this->any())
826+
->method('getLinkField')
827+
->willReturn('link');
828+
$productMock->expects($this->any())->method('hasData')
829+
->withConsecutive(['store_id'], ['_cache_instance_products'])
830+
->willReturnOnConsecutiveCalls(true, true);
831+
832+
$productMock->expects($this->any())->method('getData')
833+
->withConsecutive(['image'], ['image'], ['link'], ['store_id'], ['_cache_instance_products'])
834+
->willReturnOnConsecutiveCalls('no_selection', 'no_selection', 1, 1, [$childProductMock]);
825835

826-
$productMock->expects($this->at(0))->method('getData')->with('image')->willReturn('no_selection');
827-
$productMock->expects($this->at(1))->method('getData')->with('image')->willReturn('no_selection');
828-
$productMock->expects($this->once())->method('hasData')->with('_cache_instance_products')->willReturn(true);
829-
$productMock->expects($this->at(3))
830-
->method('getData')
831-
->with('_cache_instance_products')
832-
->willReturn([$childProductMock]);
833836
$childProductMock->expects($this->any())->method('getData')->with('image')->willReturn('image_data');
834837
$productMock->expects($this->once())->method('setImage')->with('image_data')->willReturnSelf();
835838

836839
$this->_model->setImageFromChildProduct($productMock);
837840
}
838841
}
839-

0 commit comments

Comments
 (0)