Skip to content

Commit 05fa3de

Browse files
authored
Merge pull request #8356 from magento-performance/application-server
GraphQl. Reset mutable state after request
2 parents 3d11501 + afa978d commit 05fa3de

File tree

78 files changed

+2552
-532
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+2552
-532
lines changed

app/code/Magento/Backup/Model/Fs/Collection.php

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ class Collection extends \Magento\Framework\Data\Collection\Filesystem
2929
protected $_path = 'backups';
3030

3131
/**
32-
* Backup data
33-
*
3432
* @var \Magento\Backup\Helper\Data
3533
*/
3634
protected $_backupData = null;
@@ -46,7 +44,9 @@ class Collection extends \Magento\Framework\Data\Collection\Filesystem
4644
* @var \Magento\Framework\Filesystem
4745
*/
4846
private $_filesystem;
47+
4948
/**
49+
*
5050
* @param \Magento\Framework\Data\Collection\EntityFactory $entityFactory
5151
* @param \Magento\Backup\Helper\Data $backupData
5252
* @param \Magento\Framework\Filesystem $filesystem
@@ -61,21 +61,26 @@ public function __construct(
6161
) {
6262
$this->_backupData = $backupData;
6363
parent::__construct($entityFactory, $filesystem);
64-
6564
$this->_filesystem = $filesystem;
6665
$this->_backup = $backup;
6766
$this->_varDirectory = $filesystem->getDirectoryWrite(DirectoryList::VAR_DIR);
68-
6967
$this->_hideBackupsForApache();
68+
$this->initialize();
69+
}
7070

71+
/**
72+
* Initialize collection
73+
*
74+
* @return void
75+
*/
76+
private function initialize()
77+
{
7178
// set collection specific params
7279
$extensions = $this->_backupData->getExtensions();
73-
7480
foreach ($extensions as $value) {
7581
$extensions[] = '(' . preg_quote($value, '/') . ')';
7682
}
7783
$extensions = implode('|', $extensions);
78-
7984
$this->_varDirectory->create($this->_path);
8085
$path = rtrim($this->_varDirectory->getAbsolutePath($this->_path), '/') . '/';
8186
$this->setOrder(
@@ -90,6 +95,15 @@ public function __construct(
9095
);
9196
}
9297

98+
/**
99+
* @inheritDoc
100+
*/
101+
public function _resetState(): void
102+
{
103+
parent::_resetState();
104+
$this->initialize();
105+
}
106+
93107
/**
94108
* Create .htaccess file and deny backups directory access from web
95109
*

app/code/Magento/Bundle/Pricing/Adjustment/DefaultSelectionPriceListProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,6 @@ private function getBundleOptions(Product $saleableItem)
255255
*/
256256
public function _resetState(): void
257257
{
258-
$this->priceList = [];
258+
$this->priceList = null;
259259
}
260260
}

app/code/Magento/BundleImportExport/Model/Import/Product/Type/Bundle.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
67

78
namespace Magento\BundleImportExport\Model\Import\Product\Type;
89

@@ -783,7 +784,7 @@ private function getStoreIdByCode(string $storeCode): int
783784
if (!isset($this->storeCodeToId[$storeCode])) {
784785
/** @var $store Store */
785786
foreach ($this->storeManager->getStores() as $store) {
786-
$this->storeCodeToId[$store->getCode()] = $store->getId();
787+
$this->storeCodeToId[$store->getCode()] = (int)$store->getId();
787788
}
788789
}
789790

app/code/Magento/Catalog/Helper/Product/Flat/Indexer.php

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
namespace Magento\Catalog\Helper\Product\Flat;
77

88
use Magento\Framework\App\ResourceConnection;
9+
use Magento\Framework\ObjectManager\ResetAfterRequestInterface;
910

1011
/**
1112
* Catalog Product Flat Indexer Helper
@@ -15,17 +16,17 @@
1516
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
1617
* @since 100.0.2
1718
*/
18-
class Indexer extends \Magento\Framework\App\Helper\AbstractHelper
19+
class Indexer extends \Magento\Framework\App\Helper\AbstractHelper implements ResetAfterRequestInterface
1920
{
2021
/**
2122
* Path to list of attributes used for flat indexer
2223
*/
23-
const XML_NODE_ATTRIBUTE_NODES = 'global/catalog/product/flat/attribute_groups';
24+
public const XML_NODE_ATTRIBUTE_NODES = 'global/catalog/product/flat/attribute_groups';
2425

2526
/**
2627
* Size of ids batch for reindex
2728
*/
28-
const BATCH_SIZE = 500;
29+
public const BATCH_SIZE = 500;
2930

3031
/**
3132
* Resource instance
@@ -49,7 +50,7 @@ class Indexer extends \Magento\Framework\App\Helper\AbstractHelper
4950
/**
5051
* Retrieve catalog product flat columns array in old format (used before MMDB support)
5152
*
52-
* @return array
53+
* @var array
5354
*/
5455
protected $_attributes;
5556

@@ -93,8 +94,6 @@ class Indexer extends \Magento\Framework\App\Helper\AbstractHelper
9394
protected $_flatAttributeGroups = [];
9495

9596
/**
96-
* Config factory
97-
*
9897
* @var \Magento\Catalog\Model\ResourceModel\ConfigFactory
9998
*/
10099
protected $_configFactory;
@@ -256,6 +255,7 @@ public function getFlatColumns()
256255
$this->isAddChildData()
257256
)->getFlatColumns();
258257
if ($columns !== null) {
258+
// phpcs:ignore Magento2.Performance.ForeachArrayMerge
259259
$this->_columns = array_merge($this->_columns, $columns);
260260
}
261261
}
@@ -332,6 +332,7 @@ public function getAttributeCodes()
332332

333333
foreach ($this->_flatAttributeGroups as $attributeGroupName) {
334334
$attributes = $this->_attributeConfig->getAttributeNames($attributeGroupName);
335+
// phpcs:ignore Magento2.Performance.ForeachArrayMerge
335336
$this->_systemAttributes = array_unique(array_merge($attributes, $this->_systemAttributes));
336337
}
337338

@@ -416,6 +417,7 @@ public function getFlatIndexes()
416417
$this->isAddChildData()
417418
)->getFlatIndexes();
418419
if ($indexes !== null) {
420+
// phpcs:ignore Magento2.Performance.ForeachArrayMerge
419421
$this->_indexes = array_merge($this->_indexes, $indexes);
420422
}
421423
}
@@ -515,4 +517,13 @@ public function deleteAbandonedStoreFlatTables()
515517
$connection->dropTable($table);
516518
}
517519
}
520+
521+
/**
522+
* @inheritDoc
523+
*/
524+
public function _resetState(): void
525+
{
526+
$this->_entityTypeId = null;
527+
$this->_flatAttributeGroups = [];
528+
}
518529
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,6 @@ private function getAttributes(): array
157157
*/
158158
public function _resetState(): void
159159
{
160-
$this->attributes = [];
160+
$this->attributes = null;
161161
}
162162
}

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,6 @@ class Config extends \Magento\Eav\Model\Config
8989
*/
9090
protected $_eavConfig;
9191

92-
/**
93-
* @var \Magento\Store\Model\StoreManagerInterface
94-
*/
95-
protected $_storeManager;
96-
9792
/**
9893
* @var \Magento\Eav\Model\ResourceModel\Entity\Attribute\Set\CollectionFactory
9994
*/
@@ -166,7 +161,8 @@ public function __construct(
166161
$universalFactory,
167162
$serializer,
168163
$scopeConfig,
169-
$attributesForPreload
164+
$attributesForPreload,
165+
$storeManager,
170166
);
171167
}
172168

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2840,7 +2840,7 @@ public function _resetState(): void
28402840
{
28412841
$this->_customOptions = [];
28422842
$this->_errors = [];
2843-
$this->_canAffectOptions = [];
2843+
$this->_canAffectOptions = false;
28442844
$this->_productIdCached = null;
28452845
}
28462846
}

app/code/Magento/Catalog/Model/ResourceModel/Collection/AbstractCollection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ public function __construct(
8181
*/
8282
public function _resetState(): void
8383
{
84-
parent::_resetState();
8584
$this->_storeId = null;
85+
parent::_resetState();
8686
}
8787

8888
/**

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,6 @@ public function __construct(
397397
*/
398398
public function _resetState(): void
399399
{
400-
parent::_resetState();
401400
$this->_flatEnabled = [];
402401
$this->_addUrlRewrite = false;
403402
$this->_urlRewriteCategory = '';
@@ -419,7 +418,7 @@ public function _resetState(): void
419418
$this->linkField = null;
420419
$this->backend = null;
421420
$this->emptyItem = null;
422-
$this->_construct();
421+
parent::_resetState();
423422
}
424423

425424
/**

app/code/Magento/CatalogSearch/Model/ResourceModel/Fulltext/Collection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,13 +224,13 @@ public function __construct(
224224
*/
225225
public function _resetState(): void
226226
{
227-
parent::_resetState();
228227
$this->queryText = null;
229228
$this->search = null;
230229
$this->searchCriteriaBuilder = null;
231230
$this->searchResult = null;
232231
$this->filterBuilder = null;
233232
$this->searchOrders = null;
233+
parent::_resetState();
234234
}
235235

236236
/**

app/code/Magento/Cms/Model/ResourceModel/Block/Grid/Collection.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ class Collection extends BlockCollection implements SearchResultInterface
3434
*/
3535
protected $aggregations;
3636

37+
/** @var string */
38+
private $model;
39+
40+
/** @var string */
41+
private $resourceModel;
42+
3743
/**
3844
* @param EntityFactoryInterface $entityFactory
3945
* @param LoggerInterface $logger
@@ -68,6 +74,8 @@ public function __construct(
6874
AbstractDb $resource = null,
6975
TimezoneInterface $timeZone = null
7076
) {
77+
$this->resourceModel = $resourceModel;
78+
$this->model = $model;
7179
parent::__construct(
7280
$entityFactory,
7381
$logger,
@@ -80,11 +88,20 @@ public function __construct(
8088
);
8189
$this->_eventPrefix = $eventPrefix;
8290
$this->_eventObject = $eventObject;
83-
$this->_init($model, $resourceModel);
91+
$this->_init($this->model, $this->resourceModel);
8492
$this->setMainTable($mainTable);
8593
$this->timeZone = $timeZone ?: ObjectManager::getInstance()->get(TimezoneInterface::class);
8694
}
8795

96+
/**
97+
* @inheritDoc
98+
*/
99+
public function _resetState(): void
100+
{
101+
parent::_resetState();
102+
$this->_init($this->model, $this->resourceModel);
103+
}
104+
88105
/**
89106
* @inheritDoc
90107
*/

app/code/Magento/Cms/Model/ResourceModel/Page/Grid/Collection.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ class Collection extends PageCollection implements SearchResultInterface
3434
*/
3535
protected $aggregations;
3636

37+
/** @var mixed */
38+
private $model;
39+
40+
/** @var string */
41+
private $resourceModel;
42+
3743
/**
3844
* @param EntityFactoryInterface $entityFactory
3945
* @param LoggerInterface $logger
@@ -68,6 +74,8 @@ public function __construct(
6874
AbstractDb $resource = null,
6975
TimezoneInterface $timeZone = null
7076
) {
77+
$this->resourceModel = $resourceModel;
78+
$this->model = $model;
7179
parent::__construct(
7280
$entityFactory,
7381
$logger,
@@ -80,11 +88,20 @@ public function __construct(
8088
);
8189
$this->_eventPrefix = $eventPrefix;
8290
$this->_eventObject = $eventObject;
83-
$this->_init($model, $resourceModel);
91+
$this->_init($this->model, $this->resourceModel);
8492
$this->setMainTable($mainTable);
8593
$this->timeZone = $timeZone ?: ObjectManager::getInstance()->get(TimezoneInterface::class);
8694
}
8795

96+
/**
97+
* @inheritDoc
98+
*/
99+
public function _resetState(): void
100+
{
101+
parent::_resetState();
102+
$this->_init($this->model, $this->resourceModel);
103+
}
104+
88105
/**
89106
* @inheritDoc
90107
*/

app/code/Magento/ConfigurableProduct/Model/Product/VariationHandler.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class VariationHandler implements ResetAfterRequestInterface
4545
protected $productFactory;
4646

4747
/**
48-
* @var \Magento\Eav\Model\Entity\Attribute\AbstractAttribute[]
48+
* @var \Magento\Eav\Model\Entity\Attribute\AbstractAttribute[]|null
4949
*/
5050
private $attributes;
5151

@@ -309,6 +309,6 @@ function ($image) {
309309
*/
310310
public function _resetState(): void
311311
{
312-
$this->attributes = [];
312+
$this->attributes = null;
313313
}
314314
}

app/code/Magento/ConfigurableProduct/Pricing/Price/ConfigurableOptionsProvider.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class ConfigurableOptionsProvider implements ConfigurableOptionsProviderInterfac
2222
private $configurable;
2323

2424
/**
25-
* @var ProductInterface[]
25+
* @var ProductInterface[]|null
2626
*/
2727
private $products;
2828

@@ -63,6 +63,6 @@ public function getProducts(ProductInterface $product)
6363
*/
6464
public function _resetState(): void
6565
{
66-
$this->products = [];
66+
$this->products = null;
6767
}
6868
}

app/code/Magento/Customer/Helper/Address.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ public function isAttributeVisible($code)
429429
public function _resetState(): void
430430
{
431431
$this->_config = [];
432-
$this->_attributes = [];
432+
$this->_attributes = null;
433433
$this->_streetLines = [];
434434
}
435435
}

0 commit comments

Comments
 (0)