Skip to content

Commit a38df93

Browse files
authored
Merge pull request #530 from magento-performance/ACPT-1052-part4
ACPT-1052: Some Luma Storefront Scenarios Are Broken
2 parents 6a1b2ec + 01a0cca commit a38df93

File tree

38 files changed

+491
-117
lines changed

38 files changed

+491
-117
lines changed

app/code/Magento/Bundle/Block/Catalog/Product/View/Type/Bundle.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use Magento\Framework\DataObject;
2020
use Magento\Framework\Json\EncoderInterface;
2121
use Magento\Framework\Locale\FormatInterface;
22+
use Magento\Framework\ObjectManager\ResetAfterRequestInterface;
2223
use Magento\Framework\Stdlib\ArrayUtils;
2324

2425
/**
@@ -28,7 +29,7 @@
2829
* @since 100.0.2
2930
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
3031
*/
31-
class Bundle extends AbstractView
32+
class Bundle extends AbstractView implements ResetAfterRequestInterface
3233
{
3334
/**
3435
* @var array
@@ -421,4 +422,13 @@ function (&$selection, $selectionId) use ($preConfiguredQtys) {
421422

422423
return $options;
423424
}
425+
426+
/**
427+
* @inheritDoc
428+
*/
429+
public function _resetState(): void
430+
{
431+
$this->selectedOptions = [];
432+
$this->optionsPosition = [];
433+
}
424434
}

app/code/Magento/Bundle/Model/ResourceModel/Indexer/Price/DisabledProductOptionPriceModifier.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,12 @@
1515
use Magento\Framework\EntityManager\MetadataPool;
1616
use Magento\Catalog\Model\ResourceModel\Product\Indexer\Price\PriceModifierInterface;
1717
use Magento\Bundle\Model\ResourceModel\Selection as BundleSelection;
18+
use Magento\Framework\ObjectManager\ResetAfterRequestInterface;
1819

1920
/**
2021
* Remove bundle product from price index when all products in required option are disabled
2122
*/
22-
class DisabledProductOptionPriceModifier implements PriceModifierInterface
23+
class DisabledProductOptionPriceModifier implements PriceModifierInterface, ResetAfterRequestInterface
2324
{
2425
/**
2526
* @var ResourceConnection
@@ -145,4 +146,12 @@ private function getBundleIds(array $entityIds): \Traversable
145146
yield $id;
146147
}
147148
}
149+
150+
/**
151+
* @inheritDoc
152+
*/
153+
public function _resetState(): void
154+
{
155+
$this->websiteIdsOfProduct = [];
156+
}
148157
}

app/code/Magento/BundleGraphQl/Model/Resolver/Options/Collection.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,13 @@
1111
use Magento\Framework\Api\ExtensionAttribute\JoinProcessorInterface;
1212
use Magento\Framework\App\ObjectManager;
1313
use Magento\Framework\GraphQl\Query\Uid;
14+
use Magento\Framework\ObjectManager\ResetAfterRequestInterface;
1415
use Magento\Store\Model\StoreManagerInterface;
1516

1617
/**
1718
* Collection to fetch bundle option data at resolution time.
1819
*/
19-
class Collection
20+
class Collection implements ResetAfterRequestInterface
2021
{
2122
/**
2223
* Option type name
@@ -145,4 +146,13 @@ private function fetch() : array
145146

146147
return $this->optionMap;
147148
}
149+
150+
/**
151+
* @inheritDoc
152+
*/
153+
public function _resetState(): void
154+
{
155+
$this->optionMap = [];
156+
$this->skuMap = [];
157+
}
148158
}

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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
namespace Magento\Catalog\Model;
99

10+
use Magento\Catalog\Api\CategoryRepositoryInterface;
1011
use Magento\Catalog\Model\CategoryRepository\PopulateWithValues;
1112
use Magento\Catalog\Model\ResourceModel\Category as CategoryResource;
1213
use Magento\Framework\Api\ExtensibleDataObjectConverter;
@@ -16,14 +17,17 @@
1617
use Magento\Framework\Exception\NoSuchEntityException;
1718
use Magento\Framework\Exception\StateException;
1819
use Magento\Catalog\Api\Data\CategoryInterface;
20+
use Magento\Framework\ObjectManager\ResetAfterRequestInterface;
1921
use Magento\Store\Model\StoreManagerInterface;
2022

2123
/**
2224
* Repository for categories.
2325
*
2426
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
2527
*/
26-
class CategoryRepository implements \Magento\Catalog\Api\CategoryRepositoryInterface
28+
class CategoryRepository implements
29+
CategoryRepositoryInterface,
30+
ResetAfterRequestInterface
2731
{
2832
/**
2933
* @var Category[]
@@ -230,7 +234,7 @@ protected function validateCategory(Category $category)
230234
*
231235
* @return ExtensibleDataObjectConverter
232236
*
233-
* @deprecated 101.0.0
237+
* @deprecated 101.0.0 @see we don't recommend this approach anymore
234238
*/
235239
private function getExtensibleDataObjectConverter()
236240
{
@@ -254,4 +258,12 @@ private function getMetadataPool()
254258
}
255259
return $this->metadataPool;
256260
}
261+
262+
/**
263+
* @inheritDoc
264+
*/
265+
public function _resetState(): void
266+
{
267+
$this->instances = [];
268+
}
257269
}

app/code/Magento/Catalog/Model/CategoryRepository/PopulateWithValues.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,13 @@
1515
use Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface;
1616
use Magento\Framework\Api\FilterBuilder;
1717
use Magento\Framework\Api\SearchCriteriaBuilder;
18+
use Magento\Framework\ObjectManager\ResetAfterRequestInterface;
1819
use Magento\Store\Model\Store;
1920

2021
/**
2122
* Add data to category entity and populate with default values
2223
*/
23-
class PopulateWithValues
24+
class PopulateWithValues implements ResetAfterRequestInterface
2425
{
2526
/**
2627
* @var ScopeOverriddenValue
@@ -150,4 +151,12 @@ private function getAttributes(): array
150151

151152
return $this->attributes;
152153
}
154+
155+
/**
156+
* @inheritDoc
157+
*/
158+
public function _resetState(): void
159+
{
160+
$this->attributes = [];
161+
}
153162
}

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

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Magento\Framework\App\Filesystem\DirectoryList;
1717
use Magento\Framework\App\ObjectManager;
1818
use Magento\Framework\DataObject\IdentityInterface;
19+
use Magento\Framework\ObjectManager\ResetAfterRequestInterface;
1920
use Magento\Framework\Pricing\SaleableInterface;
2021

2122
/**
@@ -43,7 +44,8 @@
4344
class Product extends \Magento\Catalog\Model\AbstractModel implements
4445
IdentityInterface,
4546
SaleableInterface,
46-
ProductInterface
47+
ProductInterface,
48+
ResetAfterRequestInterface
4749
{
4850
/**
4951
* @var ProductLinkRepositoryInterface
@@ -55,22 +57,22 @@ class Product extends \Magento\Catalog\Model\AbstractModel implements
5557
* Entity code.
5658
* Can be used as part of method name for entity processing
5759
*/
58-
const ENTITY = 'catalog_product';
60+
public const ENTITY = 'catalog_product';
5961

6062
/**
6163
* Product cache tag
6264
*/
63-
const CACHE_TAG = 'cat_p';
65+
public const CACHE_TAG = 'cat_p';
6466

6567
/**
6668
* Category product relation cache tag
6769
*/
68-
const CACHE_PRODUCT_CATEGORY_TAG = 'cat_c_p';
70+
public const CACHE_PRODUCT_CATEGORY_TAG = 'cat_c_p';
6971

7072
/**
7173
* Product Store Id
7274
*/
73-
const STORE_ID = 'store_id';
75+
public const STORE_ID = 'store_id';
7476

7577
/**
7678
* @var string|bool
@@ -170,8 +172,6 @@ class Product extends \Magento\Catalog\Model\AbstractModel implements
170172
protected $_calculatePrice = true;
171173

172174
/**
173-
* Catalog product
174-
*
175175
* @var \Magento\Catalog\Helper\Product
176176
*/
177177
protected $_catalogProduct = null;
@@ -187,43 +187,31 @@ class Product extends \Magento\Catalog\Model\AbstractModel implements
187187
protected $_collectionFactory;
188188

189189
/**
190-
* Catalog product type
191-
*
192190
* @var Product\Type
193191
*/
194192
protected $_catalogProductType;
195193

196194
/**
197-
* Catalog product media config
198-
*
199195
* @var Product\Media\Config
200196
*/
201197
protected $_catalogProductMediaConfig;
202198

203199
/**
204-
* Catalog product status
205-
*
206200
* @var Status
207201
*/
208202
protected $_catalogProductStatus;
209203

210204
/**
211-
* Catalog product visibility
212-
*
213205
* @var Product\Visibility
214206
*/
215207
protected $_catalogProductVisibility;
216208

217209
/**
218-
* Stock item factory
219-
*
220210
* @var \Magento\CatalogInventory\Api\Data\StockItemInterfaceFactory
221211
*/
222212
protected $_stockItemFactory;
223213

224214
/**
225-
* Item option factory
226-
*
227215
* @var \Magento\Catalog\Model\Product\Configuration\Item\OptionFactory
228216
*/
229217
protected $_itemOptionFactory;
@@ -279,27 +267,27 @@ class Product extends \Magento\Catalog\Model\AbstractModel implements
279267

280268
/**
281269
* @var \Magento\Catalog\Api\ProductAttributeRepositoryInterface
282-
* @deprecated 102.0.6 Not used anymore due to performance issue (loaded all product attributes)
270+
* @deprecated 102.0.6 @see Not used anymore due to performance issue (loaded all product attributes)
283271
*/
284272
protected $metadataService;
285273

286274
/**
287-
* @param \Magento\Catalog\Model\ProductLink\CollectionProvider
275+
* @var \Magento\Catalog\Model\ProductLink\CollectionProvider
288276
*/
289277
protected $entityCollectionProvider;
290278

291279
/**
292-
* @param \Magento\Catalog\Model\Product\LinkTypeProvider
280+
* @var \Magento\Catalog\Model\Product\LinkTypeProvider
293281
*/
294282
protected $linkProvider;
295283

296284
/**
297-
* @param \Magento\Catalog\Api\Data\ProductLinkInterfaceFactory
285+
* @var \Magento\Catalog\Api\Data\ProductLinkInterfaceFactory
298286
*/
299287
protected $productLinkFactory;
300288

301289
/**
302-
* @param \Magento\Catalog\Api\Data\ProductLinkExtensionFactory
290+
* @var \Magento\Catalog\Api\Data\ProductLinkExtensionFactory
303291
*/
304292
protected $productLinkExtensionFactory;
305293

@@ -494,7 +482,7 @@ protected function _construct()
494482
*
495483
* @throws \Magento\Framework\Exception\LocalizedException
496484
* @return \Magento\Catalog\Model\ResourceModel\Product
497-
* @deprecated 102.0.6 because resource models should be used directly
485+
* @deprecated 102.0.6 @see \Magento\Catalog\Model\ResourceModel\Product
498486
* @since 102.0.6
499487
*/
500488
protected function _getResource()
@@ -642,7 +630,7 @@ public function getUpdatedAt()
642630
*
643631
* @param bool $calculate
644632
* @return void
645-
* @deprecated 102.0.4
633+
* @deprecated 102.0.4 @see we don't recommend this approach anymore
646634
*/
647635
public function setPriceCalculation($calculate = true)
648636
{
@@ -2841,4 +2829,15 @@ public function setStockData($stockData)
28412829
$this->setData('stock_data', $stockData);
28422830
return $this;
28432831
}
2832+
2833+
/**
2834+
* @inheritDoc
2835+
*/
2836+
public function _resetState(): void
2837+
{
2838+
$this->_customOptions = [];
2839+
$this->_errors = [];
2840+
$this->_canAffectOptions = [];
2841+
$this->_productIdCached = null;
2842+
}
28442843
}

app/code/Magento/Catalog/Model/Product/Image/Cache.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@
77

88
use Magento\Catalog\Helper\Image as ImageHelper;
99
use Magento\Catalog\Model\Product;
10+
use Magento\Framework\ObjectManager\ResetAfterRequestInterface;
1011
use Magento\Theme\Model\ResourceModel\Theme\Collection as ThemeCollection;
1112
use Magento\Framework\App\Area;
1213
use Magento\Framework\View\ConfigInterface;
1314

14-
class Cache
15+
class Cache implements ResetAfterRequestInterface
1516
{
1617
/**
1718
* @var ConfigInterface
@@ -66,6 +67,7 @@ protected function getData()
6667
]);
6768
$images = $config->getMediaEntities('Magento_Catalog', ImageHelper::MEDIA_TYPE_CONFIG_NODE);
6869
foreach ($images as $imageId => $imageData) {
70+
// phpcs:ignore Magento2.Performance.ForeachArrayMerge
6971
$this->data[$theme->getCode() . $imageId] = array_merge(['id' => $imageId], $imageData);
7072
}
7173
}
@@ -127,4 +129,12 @@ protected function processImageData(Product $product, array $imageData, $file)
127129

128130
return $this;
129131
}
132+
133+
/**
134+
* @inheritDoc
135+
*/
136+
public function _resetState(): void
137+
{
138+
$this->data = [];
139+
}
130140
}

app/code/Magento/Catalog/Model/Product/Media/Config.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
namespace Magento\Catalog\Model\Product\Media;
88

99
use Magento\Eav\Model\Entity\Attribute;
10+
use Magento\Framework\ObjectManager\ResetAfterRequestInterface;
1011
use Magento\Framework\UrlInterface;
1112
use Magento\Store\Model\StoreManagerInterface;
1213

@@ -16,7 +17,7 @@
1617
* @api
1718
* @since 100.0.2
1819
*/
19-
class Config implements ConfigInterface
20+
class Config implements ConfigInterface, ResetAfterRequestInterface
2021
{
2122
/**
2223
* @var StoreManagerInterface
@@ -199,4 +200,12 @@ private function getAttributeHelper()
199200
}
200201
return $this->attributeHelper;
201202
}
203+
204+
/**
205+
* @inheritDoc
206+
*/
207+
public function _resetState(): void
208+
{
209+
$this->mediaAttributeCodes = [];
210+
}
202211
}

0 commit comments

Comments
 (0)