Skip to content

Commit ea257d6

Browse files
authored
Merge pull request #8552 from magento-performance/ACPT-1599-2.4.7-beta2-develop
ACPT-1599: Fixing DeploymentConfig resets & reloads every time new key that wasn't previously set
2 parents 2932016 + 4d3ed81 commit ea257d6

File tree

3 files changed

+58
-22
lines changed

3 files changed

+58
-22
lines changed

lib/internal/Magento/Framework/App/DeploymentConfig.php

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,6 @@ class DeploymentConfig
6161
*/
6262
private $readerLoad = [];
6363

64-
/**
65-
* @var array
66-
*/
67-
private $noConfigData = [];
68-
6964
/**
7065
* Constructor
7166
*
@@ -99,17 +94,9 @@ public function get($key = null, $defaultValue = null)
9994
}
10095
$result = $this->getByKey($key);
10196
if ($result === null) {
102-
if (empty($this->flatData)
103-
|| !isset($this->flatData[$key]) && !isset($this->noConfigData[$key])
104-
|| count($this->getAllEnvOverrides())
105-
) {
106-
$this->resetData();
97+
if (empty($this->flatData) || count($this->getAllEnvOverrides())) {
10798
$this->reloadData();
10899
}
109-
110-
if (!isset($this->flatData[$key])) {
111-
$this->noConfigData[$key] = $key;
112-
}
113100
$result = $this->getByKey($key);
114101
}
115102
return $result ?? $defaultValue;

lib/internal/Magento/Framework/App/Test/Unit/DeploymentConfigTest.php

Lines changed: 41 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -306,15 +306,11 @@ public function testEnvVariablesSubstitution(): void
306306
* @throws FileSystemException
307307
* @throws RuntimeException
308308
*/
309-
public function testReloadDataOnMissingConfig(): void
309+
public function testShouldntReloadDataOnMissingConfig(): void
310310
{
311-
$this->readerMock->expects($this->exactly(2))
311+
$this->readerMock->expects($this->once())
312312
->method('load')
313-
->willReturnOnConsecutiveCalls(
314-
['db' => ['connection' => ['default' => ['host' => 'localhost']]]],
315-
[],
316-
[]
317-
);
313+
->willReturn(['db' => ['connection' => ['default' => ['host' => 'localhost']]]]);
318314
$connectionConfig1 = $this->deploymentConfig->get(
319315
ConfigOptionsListConstants::CONFIG_PATH_DB_CONNECTIONS . '/' . 'default'
320316
);
@@ -330,4 +326,42 @@ public function testReloadDataOnMissingConfig(): void
330326
$result3 = $this->deploymentConfig->get('missing/key');
331327
$this->assertNull($result3);
332328
}
329+
330+
/**
331+
* @return void
332+
*/
333+
public function testShouldntLoadMultipleTimes() : void
334+
{
335+
$this->readerMock->expects($this->once())->method('load')
336+
->willReturn(['a' => ['a' => ['a' => 1]]]);
337+
$this->deploymentConfig->get('a/a/a');
338+
$this->deploymentConfig->get('a/a/b');
339+
$this->deploymentConfig->get('a/a/c');
340+
$this->deploymentConfig->get('a/b/a');
341+
$this->deploymentConfig->get('a/b/b');
342+
$this->deploymentConfig->get('a/b/c');
343+
}
344+
345+
/**
346+
* @return void
347+
*/
348+
public function testShouldReloadPreviouslyUnsetKeysAfterReset() : void
349+
{
350+
$testValue = 42;
351+
$loadReturn = ['a' => ['a' => ['a' => 1]]];
352+
$this->readerMock->expects($this->any())->method('load')
353+
->will($this->returnCallback(
354+
function () use (&$loadReturn) {
355+
return $loadReturn;
356+
}
357+
));
358+
$this->deploymentConfig->get('a/a/a');
359+
$abcReturnValue1 = $this->deploymentConfig->get('a/b/c');
360+
$this->assertNull($abcReturnValue1); // first try, it isn't set yet.
361+
$loadReturn = ['a' => ['a' => ['a' => 1], 'b' => ['c' => $testValue]]];
362+
$this->deploymentConfig->resetData();
363+
$this->deploymentConfig->get('a/a/a');
364+
$abcReturnValue2 = $this->deploymentConfig->get('a/b/c');
365+
$this->assertEquals($testValue, $abcReturnValue2); // second try, it should load the newly set value
366+
}
333367
}

setup/src/Magento/Setup/Model/Installer.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,12 @@
1212
use Magento\Framework\App\Cache\Type\Block as BlockCache;
1313
use Magento\Framework\App\Cache\Type\Config as ConfigCache;
1414
use Magento\Framework\App\Cache\Type\Layout as LayoutCache;
15+
use Magento\Framework\App\DeploymentConfig;
1516
use Magento\Framework\App\DeploymentConfig\Reader;
1617
use Magento\Framework\App\DeploymentConfig\Writer;
1718
use Magento\Framework\App\Filesystem\DirectoryList;
1819
use Magento\Framework\App\MaintenanceMode;
20+
use Magento\Framework\App\ObjectManager;
1921
use Magento\Framework\App\State\CleanupFiles;
2022
use Magento\Framework\Component\ComponentRegistrar;
2123
use Magento\Framework\Config\ConfigOptionsListConstants;
@@ -178,10 +180,15 @@ class Installer
178180
private $installInfo = [];
179181

180182
/**
181-
* @var \Magento\Framework\App\DeploymentConfig
183+
* @var DeploymentConfig
182184
*/
183185
private $deploymentConfig;
184186

187+
/**
188+
* @var DeploymentConfig
189+
*/
190+
private $firstDeploymentConfig;
191+
185192
/**
186193
* @var ObjectManagerProvider
187194
*/
@@ -330,6 +337,11 @@ public function __construct(
330337
$this->phpReadinessCheck = $phpReadinessCheck;
331338
$this->schemaPersistor = $this->objectManagerProvider->get()->get(SchemaPersistor::class);
332339
$this->triggerCleaner = $this->objectManagerProvider->get()->get(TriggerCleaner::class);
340+
/* Note: Because this class is dependency injected with Laminas ServiceManager, but our plugins, and some
341+
* other classes also use the App\ObjectManager instead, we have to make sure that the DeploymentConfig object
342+
* from that ObjectManager gets reset as different steps in the installer will write to the deployment config.
343+
*/
344+
$this->firstDeploymentConfig = ObjectManager::getInstance()->get(DeploymentConfig::class);
333345
}
334346

335347
/**
@@ -389,6 +401,9 @@ public function install($request)
389401
$this->log->log('Starting Magento installation:');
390402

391403
foreach ($script as $item) {
404+
/* Note: Because the $this->DeploymentConfig gets written to, but plugins use $this->firstDeploymentConfig,
405+
* we have to reset this one after each item of $script so the plugins will see the config updates. */
406+
$this->firstDeploymentConfig->resetData();
392407
list($message, $method, $params) = $item;
393408
$this->log->log($message);
394409
try {

0 commit comments

Comments
 (0)