Skip to content

Commit f327620

Browse files
authored
Merge pull request #562 from magento-performance/ACPT-1551
ACPT-1551: Modularity of ReloadProcessor::reloadApplicationState
2 parents ee8ac1e + 62a9208 commit f327620

File tree

10 files changed

+234
-0
lines changed

10 files changed

+234
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
namespace Magento\Config\App\Config;
8+
9+
use Magento\Config\App\Config\Type\System;
10+
use Magento\Framework\App\State\ReloadProcessorInterface;
11+
use Magento\Framework\ObjectManagerInterface;
12+
13+
/**
14+
* Config module specific reset state
15+
*/
16+
class ReloadConfig implements ReloadProcessorInterface
17+
{
18+
public function __construct(private readonly System $system)
19+
{}
20+
21+
/**
22+
* Tells the system state to reload itself.
23+
*
24+
* @param ObjectManagerInterface $objectManager
25+
* @return void
26+
*/
27+
public function reloadState(): void
28+
{
29+
$this->system->get();
30+
}
31+
}

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,4 +390,11 @@
390390
<type name="Magento\Framework\App\Cache\TypeList">
391391
<plugin name="warm_config_cache" type="Magento\Config\Plugin\Framework\App\Cache\TypeList\WarmConfigCache"/>
392392
</type>
393+
<type name="Magento\Framework\App\State\ReloadProcessorComposite">
394+
<arguments>
395+
<argument name="processors" xsi:type="array">
396+
<item name="Magento_Config::config" xsi:type="object">Magento\Config\App\Config\ReloadConfig</item>
397+
</argument>
398+
</arguments>
399+
</type>
393400
</config>
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
namespace Magento\Store\Model\Config;
8+
9+
use Magento\Framework\App\State\ReloadProcessorInterface;
10+
use Magento\Framework\ObjectManagerInterface;
11+
use Magento\Store\App\Config\Type\Scopes;
12+
use Magento\Store\Model\GroupRepository;
13+
use Magento\Store\Model\StoreRepository;
14+
use Magento\Store\Model\WebsiteRepository;
15+
16+
/**
17+
* Store module specific reset state part
18+
*/
19+
class ReloadDeploymentConfig implements ReloadProcessorInterface
20+
{
21+
22+
public function __construct(
23+
private readonly StoreRepository $storeRepository,
24+
private readonly WebsiteRepository $websiteRepository,
25+
private readonly GroupRepository $groupRepository,
26+
private readonly Scopes $scopes
27+
)
28+
{}
29+
30+
/**
31+
* Tells the system state to reload itself.
32+
*
33+
* @param ObjectManagerInterface $objectManager
34+
* @return void
35+
*/
36+
public function reloadState(): void
37+
{
38+
// Note: Magento\Store\Model\StoreManager::reinitStores can't be called because it flushes the caches which
39+
// we don't want to do because that is already taken care of. Instead, we call the same clean methods that
40+
// it calls, but we skip cleaning the cache.
41+
42+
$this->storeRepository->clean();
43+
$this->websiteRepository->clean();
44+
$this->groupRepository->clean();
45+
46+
$this->scopes->clean();
47+
$this->scopes->get();
48+
}
49+
}

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,4 +467,11 @@
467467
</argument>
468468
</arguments>
469469
</type>
470+
<type name="Magento\Framework\App\State\ReloadProcessorComposite">
471+
<arguments>
472+
<argument name="processors" xsi:type="array">
473+
<item name="Magento_ApplicationServer::process" xsi:type="object">Magento\Store\Model\Config\ReloadDeploymentConfig</item>
474+
</argument>
475+
</arguments>
476+
</type>
470477
</config>
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
namespace Magento\Translation\App\Config;
8+
9+
use Magento\Framework\App\State\ReloadProcessorInterface;
10+
use Magento\Framework\ObjectManagerInterface;
11+
use Magento\Translation\App\Config\Type\Translation;
12+
13+
/**
14+
* Translation module specific reset state part
15+
*/
16+
class ReloadConfig implements ReloadProcessorInterface
17+
{
18+
/**
19+
* @param Translation $translation
20+
*/
21+
public function __construct(private readonly Translation $translation)
22+
{}
23+
24+
/**
25+
* Tells the system state to reload itself.
26+
*
27+
* @param ObjectManagerInterface $objectManager
28+
* @return void
29+
*/
30+
public function reloadState(): void
31+
{
32+
$this->translation->clean();
33+
}
34+
}

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,4 +149,11 @@
149149
</argument>
150150
</arguments>
151151
</type>
152+
<type name="Magento\Framework\App\State\ReloadProcessorComposite">
153+
<arguments>
154+
<argument name="processors" xsi:type="array">
155+
<item name="Magento_Translate::config" xsi:type="object">Magento\Translation\App\Config\ReloadConfig</item>
156+
</argument>
157+
</arguments>
158+
</type>
152159
</config>

app/etc/di.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2004,4 +2004,12 @@
20042004
</type>
20052005
<preference for="Magento\Framework\Filter\Input\PurifierInterface" type="Magento\Framework\Filter\Input\Purifier"/>
20062006
<preference for="Magento\Framework\App\PageCache\IdentifierInterface" type="Magento\Framework\App\PageCache\Identifier"/>
2007+
<preference for="Magento\Framework\App\State\ReloadProcessorInterface" type="Magento\Framework\App\State\ReloadProcessorComposite" />
2008+
<type name="Magento\Framework\App\State\ReloadProcessorComposite">
2009+
<arguments>
2010+
<argument name="processors" xsi:type="array">
2011+
<item name="config" xsi:type="object">Magento\Framework\App\State\ReloadProcessor</item>
2012+
</argument>
2013+
</arguments>
2014+
</type>
20072015
</config>
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
namespace Magento\Framework\App\State;
8+
9+
use Magento\Framework\App\Config\ScopeCodeResolver;
10+
use Magento\Framework\App\DeploymentConfig;
11+
use Magento\Framework\ObjectManagerInterface;
12+
13+
/**
14+
* Framework specific reset state
15+
*/
16+
class ReloadProcessor implements ReloadProcessorInterface
17+
{
18+
19+
public function __construct(
20+
private readonly DeploymentConfig $deploymentConfig,
21+
private readonly ScopeCodeResolver $scopeCodeResolver
22+
)
23+
{}
24+
25+
/**
26+
* Tells the system state to reload itself.
27+
*
28+
* @param ObjectManagerInterface $objectManager
29+
* @return void
30+
*/
31+
public function reloadState(): void
32+
{
33+
$this->deploymentConfig->resetData();
34+
$this->scopeCodeResolver->clean();
35+
}
36+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
namespace Magento\Framework\App\State;
8+
9+
use \Magento\Framework\ObjectManagerInterface;
10+
11+
/**
12+
* Composite of reload processors
13+
*/
14+
class ReloadProcessorComposite implements ReloadProcessorInterface
15+
{
16+
/**
17+
* @param ReloadProcessorInterface[] $processors
18+
*/
19+
public function __construct(private array $processors)
20+
{}
21+
22+
/**
23+
* {@inheritdoc}
24+
*/
25+
public function reloadState(): void
26+
{
27+
ksort($this->processors);
28+
/** @var ReloadProcessorInterface $processor */
29+
foreach ($this->processors as $processor) {
30+
$processor->reloadState();
31+
}
32+
}
33+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
namespace Magento\Framework\App\State;
8+
9+
use \Magento\Framework\ObjectManagerInterface;
10+
11+
/**
12+
*
13+
*/
14+
interface ReloadProcessorInterface
15+
{
16+
/**
17+
* Tells the system state to reload itself.
18+
*
19+
* @return void
20+
*/
21+
public function reloadState(): void;
22+
}

0 commit comments

Comments
 (0)