Skip to content

Commit c4c4535

Browse files
committed
MC-38593: Complex products children ids are not cached in Type class leading to multiple unnecessary db requests
1 parent 918e1d3 commit c4c4535

File tree

4 files changed

+19
-6
lines changed

4 files changed

+19
-6
lines changed

app/code/Magento/Bundle/Model/Plugin/Frontend/ProductIdentitiesExtender.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public function afterGetIdentities(CatalogProduct $product, array $identities):
6060
* @param mixed $entityId
6161
* @return array
6262
*/
63-
private function getChildrenIds($entityId)
63+
private function getChildrenIds($entityId): array
6464
{
6565
if (!isset($this->cacheChildrenIds[$entityId])) {
6666
$this->cacheChildrenIds[$entityId] = $this->type->getChildrenIds($entityId);

app/code/Magento/Bundle/Model/Plugin/ProductIdentitiesExtender.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
use Magento\Bundle\Model\Product\Type as BundleType;
1111
use Magento\Catalog\Model\Product as CatalogProduct;
1212

13+
/**
14+
* Add parent identities to product identities.
15+
*/
1316
class ProductIdentitiesExtender
1417
{
1518
/**
@@ -47,6 +50,7 @@ public function afterGetIdentities(
4750
foreach ($this->getParentIdsByChild($product->getEntityId()) as $parentId) {
4851
$identities[] = CatalogProduct::CACHE_TAG . '_' . $parentId;
4952
}
53+
5054
return $identities;
5155
}
5256

@@ -56,7 +60,7 @@ public function afterGetIdentities(
5660
* @param mixed $entityId
5761
* @return array
5862
*/
59-
private function getParentIdsByChild($entityId)
63+
private function getParentIdsByChild($entityId): array
6064
{
6165
if (!isset($this->cacheParentIdsByChild[$entityId])) {
6266
$this->cacheParentIdsByChild[$entityId] = $this->type->getParentIdsByChild($entityId);

app/code/Magento/Bundle/Test/Unit/Model/Plugin/Frontend/ProductIdentitiesExtenderTest.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,23 @@
1313
use PHPUnit\Framework\MockObject\MockObject;
1414
use PHPUnit\Framework\TestCase;
1515

16+
/**
17+
* Unit test for \Magento\Bundle\Model\Plugin\Frontend\ProductIdentitiesExtender
18+
*/
1619
class ProductIdentitiesExtenderTest extends TestCase
1720
{
18-
/** @var \Magento\Bundle\Model\Plugin\Product */
21+
/** @var ProductPlugin */
1922
private $plugin;
2023

21-
/** @var MockObject|Type */
24+
/** @var MockObject|Type */
2225
private $type;
2326

24-
/** @var MockObject|\Magento\Catalog\Model\Product */
27+
/** @var MockObject|Product */
2528
private $product;
2629

30+
/**
31+
* @inheritdoc
32+
*/
2733
protected function setUp(): void
2834
{
2935
$this->product = $this->getMockBuilder(Product::class)
@@ -39,7 +45,7 @@ protected function setUp(): void
3945
$this->plugin = new ProductPlugin($this->type);
4046
}
4147

42-
public function testAfterGetIdentities()
48+
public function testAfterGetIdentities(): void
4349
{
4450
$baseIdentities = [
4551
'SomeCacheId',

app/code/Magento/Bundle/Test/Unit/Model/Plugin/ProductIdentitiesExtenderTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
use PHPUnit\Framework\MockObject\MockObject;
1515
use PHPUnit\Framework\TestCase;
1616

17+
/**
18+
* Unit test for \Magento\Bundle\Model\Plugin\ProductIdentitiesExtender
19+
*/
1720
class ProductIdentitiesExtenderTest extends TestCase
1821
{
1922
/** @var Plugin */

0 commit comments

Comments
 (0)