Skip to content

Commit 908ef9f

Browse files
committed
MAGETWO-65145: Performance degradation on front end on configurable products with huge amount of variation
1 parent defd39c commit 908ef9f

File tree

7 files changed

+24
-32
lines changed

7 files changed

+24
-32
lines changed

app/code/Magento/ConfigurableProduct/Model/AttributeOptionProvider.php

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
use Magento\Framework\DB\Select;
1313

1414
/**
15-
* Class AttributeOptionProvider.
15+
* Provider for retrieving configurable options.
1616
*/
1717
class AttributeOptionProvider implements AttributeOptionProviderInterface
1818
{
@@ -29,23 +29,21 @@ class AttributeOptionProvider implements AttributeOptionProviderInterface
2929
/**
3030
* @var OptionSelectBuilderInterface
3131
*/
32-
private $optionSelectBuilderInterface;
32+
private $optionSelectBuilder;
3333

3434
/**
35-
* AttributeOptionProvider constructor.
36-
*
3735
* @param Attribute $attributeResource
3836
* @param ScopeResolverInterface $scopeResolver,
39-
* @param OptionSelectBuilderInterface $optionSelectBuilderInterface
37+
* @param OptionSelectBuilderInterface $optionSelectBuilder
4038
*/
4139
public function __construct(
4240
Attribute $attributeResource,
4341
ScopeResolverInterface $scopeResolver,
44-
OptionSelectBuilderInterface $optionSelectBuilderInterface
42+
OptionSelectBuilderInterface $optionSelectBuilder
4543
) {
4644
$this->attributeResource = $attributeResource;
4745
$this->scopeResolver = $scopeResolver;
48-
$this->optionSelectBuilderInterface = $optionSelectBuilderInterface;
46+
$this->optionSelectBuilder = $optionSelectBuilder;
4947
}
5048

5149
/**
@@ -54,7 +52,7 @@ public function __construct(
5452
public function getAttributeOptions(AbstractAttribute $superAttribute, $productId)
5553
{
5654
$scope = $this->scopeResolver->getScope();
57-
$select = $this->optionSelectBuilderInterface->getSelect($superAttribute, $productId, $scope);
55+
$select = $this->optionSelectBuilder->getSelect($superAttribute, $productId, $scope);
5856

5957
return $this->attributeResource->getConnection()->fetchAll($select);
6058
}

app/code/Magento/ConfigurableProduct/Model/ResourceModel/Attribute/OptionSelectBuilder.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
use Magento\Framework\DB\Select;
1212

1313
/**
14-
* Class AttributeOptionSelectBuilder.
14+
* Build select object for retrieving configurable options.
1515
*/
1616
class OptionSelectBuilder implements OptionSelectBuilderInterface
1717
{
@@ -30,8 +30,6 @@ class OptionSelectBuilder implements OptionSelectBuilderInterface
3030
private $attributeOptionProvider;
3131

3232
/**
33-
* Constructor.
34-
*
3533
* @param Attribute $attributeResource
3634
* @param OptionProvider $attributeOptionProvider
3735
*/
@@ -44,7 +42,7 @@ public function __construct(Attribute $attributeResource, OptionProvider $attrib
4442
/**
4543
* {@inheritdoc}
4644
*/
47-
public function getSelect(AbstractAttribute $superAttribute, $productId, ScopeInterface $scope)
45+
public function getSelect(AbstractAttribute $superAttribute, int $productId, ScopeInterface $scope)
4846
{
4947
$select = $this->attributeResource->getConnection()->select()->from(
5048
['super_attribute' => $this->attributeResource->getTable('catalog_product_super_attribute')],

app/code/Magento/ConfigurableProduct/Model/ResourceModel/Attribute/OptionSelectBuilderInterface.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,17 @@
1010
use Magento\Framework\DB\Select;
1111

1212
/**
13-
* AttributeOptionSelectBuilderInterface
13+
* Interface to build select for retrieving configurable options.
1414
*/
1515
interface OptionSelectBuilderInterface
1616
{
1717
/**
18-
* Get load options for attribute select
18+
* Get load options for attribute select.
1919
*
2020
* @param AbstractAttribute $superAttribute
2121
* @param int $productId
2222
* @param ScopeInterface $scope
2323
* @return Select
2424
*/
25-
public function getSelect(AbstractAttribute $superAttribute, $productId, ScopeInterface $scope);
25+
public function getSelect(AbstractAttribute $superAttribute, int $productId, ScopeInterface $scope);
2626
}
Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,13 @@
66
namespace Magento\ConfigurableProduct\Plugin\Model\ResourceModel\Attribute;
77

88
use Magento\CatalogInventory\Model\ResourceModel\Stock\Status;
9-
use Magento\ConfigurableProduct\Model\ResourceModel\Attribute\OptionSelectBuilderInterface as OptionSelectBuilder;
9+
use Magento\ConfigurableProduct\Model\ResourceModel\Attribute\OptionSelectBuilderInterface;
1010
use Magento\Framework\DB\Select;
1111

12-
1312
/**
1413
* Plugin for Class OptionSelectBuilderInterface.
1514
*/
16-
class OptionSelectBuilderInterface
15+
class InStockOptionSelectBuilder
1716
{
1817
/**
1918
* CatalogInventory Stock Status Resource Model
@@ -33,13 +32,13 @@ public function __construct(Status $stockStatusResource)
3332
/**
3433
* Add stock status filter to select.
3534
*
36-
* @param OptionSelectBuilder $subject
35+
* @param OptionSelectBuilderInterface $subject
3736
* @param Select $select
3837
* @return Select
3938
*
4039
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
4140
*/
42-
public function afterGetSelect(OptionSelectBuilder $subject, Select $select)
41+
public function afterGetSelect(OptionSelectBuilderInterface $subject, Select $select)
4342
{
4443
$select->joinInner(
4544
['stock' => $this->stockStatusResource->getMainTable()],

app/code/Magento/ConfigurableProduct/Test/Unit/Model/AttributeOptionProviderTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ class AttributeOptionProviderTest extends \PHPUnit_Framework_TestCase
6464
/**
6565
* @var OptionSelectBuilderInterface|\PHPUnit_Framework_MockObject_MockObject
6666
*/
67-
private $optionSelectBuilderInterface;
67+
private $optionSelectBuilder;
6868

6969
protected function setUp()
7070
{
@@ -89,7 +89,7 @@ protected function setUp()
8989
->disableOriginalConstructor()
9090
->getMock();
9191

92-
$this->optionSelectBuilderInterface = $this->getMockBuilder(OptionSelectBuilderInterface::class)
92+
$this->optionSelectBuilder = $this->getMockBuilder(OptionSelectBuilderInterface::class)
9393
->disableOriginalConstructor()
9494
->getMockForAbstractClass();
9595

@@ -104,7 +104,7 @@ protected function setUp()
104104
[
105105
'attributeResource' => $this->attributeResource,
106106
'scopeResolver' => $this->scopeResolver,
107-
'optionSelectBuilderInterface' => $this->optionSelectBuilderInterface,
107+
'optionSelectBuilder' => $this->optionSelectBuilder,
108108
]
109109
);
110110
}
@@ -119,7 +119,7 @@ public function testGetAttributeOptions(array $options)
119119
->method('getScope')
120120
->willReturn($this->scope);
121121

122-
$this->optionSelectBuilderInterface->expects($this->any())
122+
$this->optionSelectBuilder->expects($this->any())
123123
->method('getSelect')
124124
->with($this->abstractAttribute, 4, $this->scope)
125125
->willReturn($this->select);
Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,14 @@
88

99
use Magento\CatalogInventory\Model\ResourceModel\Stock\Status;
1010
use Magento\ConfigurableProduct\Model\ResourceModel\Attribute\OptionSelectBuilder;
11-
use Magento\ConfigurableProduct\Plugin\Model\ResourceModel\Attribute\OptionSelectBuilderInterface;
11+
use Magento\ConfigurableProduct\Plugin\Model\ResourceModel\Attribute\InStockOptionSelectBuilder;
1212
use Magento\Framework\DB\Select;
1313
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
1414

15-
/**
16-
* Class OptionSelectBuilderInterfaceTest.
17-
*/
18-
class OptionSelectBuilderInterfaceTest extends \PHPUnit_Framework_TestCase
15+
class InStockOptionSelectBuilderTest extends \PHPUnit_Framework_TestCase
1916
{
2017
/**
21-
* @var OptionSelectBuilderInterface
18+
* @var InStockOptionSelectBuilder
2219
*/
2320
private $model;
2421

@@ -59,7 +56,7 @@ protected function setUp()
5956

6057
$this->objectManagerHelper = new ObjectManager($this);
6158
$this->model = $this->objectManagerHelper->getObject(
62-
OptionSelectBuilderInterface::class,
59+
InStockOptionSelectBuilder::class,
6360
[
6461
'stockStatusResource' => $this->stockStatusResourceMock,
6562
]

app/code/Magento/ConfigurableProduct/etc/frontend/di.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@
1515
</arguments>
1616
</type>
1717
<type name="Magento\ConfigurableProduct\Model\ResourceModel\Attribute\OptionSelectBuilderInterface">
18-
<plugin name="Magento_ConfigurableProduct_Plugin_Model_ResourceModel_Attribute_OptionSelectBuilderInterface" type="Magento\ConfigurableProduct\Plugin\Model\ResourceModel\Attribute\OptionSelectBuilderInterface"/>
18+
<plugin name="Magento_ConfigurableProduct_Plugin_Model_ResourceModel_Attribute_InStockOptionSelectBuilder" type="Magento\ConfigurableProduct\Plugin\Model\ResourceModel\Attribute\InStockOptionSelectBuilder"/>
1919
</type>
2020
</config>

0 commit comments

Comments
 (0)