Skip to content

Commit 7599c36

Browse files
authored
Merge pull request #864 from magento-nord/SPRINT-30-NORD
- MAGETWO-64890: Catalog performance improvement
2 parents 0b25aec + 96a4f43 commit 7599c36

File tree

4 files changed

+41
-11
lines changed

4 files changed

+41
-11
lines changed

app/code/Magento/Catalog/Model/ProductIdLocator.php

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,16 @@
88

99
/**
1010
* Product ID locator provides all product IDs by SKUs.
11-
* @api
1211
*/
1312
class ProductIdLocator implements \Magento\Catalog\Model\ProductIdLocatorInterface
1413
{
14+
/**
15+
* Limit values for array IDs by SKU.
16+
*
17+
* @var int
18+
*/
19+
private $idsLimit;
20+
1521
/**
1622
* Metadata pool.
1723
*
@@ -34,13 +40,16 @@ class ProductIdLocator implements \Magento\Catalog\Model\ProductIdLocatorInterfa
3440
/**
3541
* @param \Magento\Framework\EntityManager\MetadataPool $metadataPool
3642
* @param \Magento\Catalog\Model\ResourceModel\Product\CollectionFactory $collectionFactory
43+
* @param string $limitIdsBySkuValues
3744
*/
3845
public function __construct(
3946
\Magento\Framework\EntityManager\MetadataPool $metadataPool,
40-
\Magento\Catalog\Model\ResourceModel\Product\CollectionFactory $collectionFactory
47+
\Magento\Catalog\Model\ResourceModel\Product\CollectionFactory $collectionFactory,
48+
$idsLimit
4149
) {
4250
$this->metadataPool = $metadataPool;
4351
$this->collectionFactory = $collectionFactory;
52+
$this->idsLimit = (int)$idsLimit;
4453
}
4554

4655
/**
@@ -75,7 +84,19 @@ public function retrieveProductIdsBySkus(array $skus)
7584
$productIds[$sku] = $this->idsBySku[$unifiedSku];
7685
}
7786
}
78-
87+
$this->truncateToLimit();
7988
return $productIds;
8089
}
90+
91+
/**
92+
* Cleanup IDs by SKU cache more than some limit.
93+
*
94+
* @return void
95+
*/
96+
private function truncateToLimit()
97+
{
98+
if (count($this->idsBySku) > $this->idsLimit) {
99+
$this->idsBySku = array_slice($this->idsBySku, round($this->idsLimit / -2));
100+
}
101+
}
81102
}

app/code/Magento/Catalog/Model/ProductIdLocatorInterface.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
/**
99
* Product ID locator provides all product IDs by SKU.
10+
* @api
1011
*/
1112
interface ProductIdLocatorInterface
1213
{

app/code/Magento/Catalog/etc/di.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,11 @@
157157
<argument name="perPageValues" xsi:type="string">9,15,30</argument>
158158
</arguments>
159159
</type>
160+
<type name="Magento\Catalog\Model\ProductIdLocator">
161+
<arguments>
162+
<argument name="idsLimit" xsi:type="number">1000</argument>
163+
</arguments>
164+
</type>
160165
<type name="Magento\Catalog\Model\Config\Source\ListPerPage">
161166
<arguments>
162167
<argument name="options" xsi:type="string">5,10,15,20,25</argument>

dev/tests/integration/testsuite/Magento/Customer/Model/Config/Source/Group/MultiselectTest.php

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,16 @@ public function testToOptionArray()
2929
}
3030
}
3131
sort($optionsToCompare);
32-
$this->assertEquals(
33-
[
34-
['value' => 1, 'label' => 'General'],
35-
['value' => 2, 'label' => 'Wholesale'],
36-
['value' => 3, 'label' => 'Retailer'],
37-
],
38-
$optionsToCompare
39-
);
32+
foreach ($optionsToCompare as $item) {
33+
$this->assertContains(
34+
$item,
35+
[
36+
['value' => 1, 'label' => 'Default (General)'],
37+
['value' => 1, 'label' => 'General'],
38+
['value' => 2, 'label' => 'Wholesale'],
39+
['value' => 3, 'label' => 'Retailer'],
40+
]
41+
);
42+
}
4043
}
4144
}

0 commit comments

Comments
 (0)