Skip to content

Commit 992ca88

Browse files
alzotao-iegorov
authored andcommitted
ACP2E-1958: avoid reloading configs for each requested key; added unit tests
1 parent 9b839c0 commit 992ca88

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

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

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ class DeploymentConfig
5656
*/
5757
private $envOverrides = [];
5858

59+
/**
60+
* @var array
61+
*/
62+
private $readerLoad = [];
63+
5964
/**
6065
* Constructor
6166
*
@@ -122,13 +127,13 @@ public function getConfigData($key = null)
122127
{
123128
if ($key === null) {
124129
if (empty($this->data)) {
125-
$this->reloadData();
130+
$this->reloadInitialData();
126131
}
127132
return $this->data;
128133
}
129134
$result = $this->getConfigDataByKey($key);
130135
if ($result === null) {
131-
$this->reloadData();
136+
$this->reloadInitialData();
132137
$result = $this->getConfigDataByKey($key);
133138
}
134139
return $result;
@@ -178,13 +183,28 @@ private function getEnvOverride() : array
178183
* @throws FileSystemException
179184
* @throws RuntimeException
180185
*/
181-
private function reloadData(): void
186+
private function reloadInitialData(): void
182187
{
188+
if (empty($this->readerLoad)) {
189+
$this->readerLoad = $this->reader->load();
190+
}
183191
$this->data = array_replace(
184-
$this->reader->load(),
192+
$this->readerLoad,
185193
$this->overrideData ?? [],
186194
$this->getEnvOverride()
187195
);
196+
}
197+
198+
/**
199+
* Loads the configuration data
200+
*
201+
* @return void
202+
* @throws FileSystemException
203+
* @throws RuntimeException
204+
*/
205+
private function reloadData(): void
206+
{
207+
$this->reloadInitialData();
188208
// flatten data for config retrieval using get()
189209
$this->flatData = $this->flattenParams($this->data);
190210
$this->flatData = $this->getAllEnvOverrides() + $this->flatData;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ public function keyCollisionDataProvider(): array
228228
*/
229229
public function testResetData(): void
230230
{
231-
$this->readerMock->expects($this->exactly(2))->method('load')->willReturn(self::$fixture);
231+
$this->readerMock->expects($this->exactly(1))->method('load')->willReturn(self::$fixture);
232232
$this->assertSame(self::$flattenedFixture, $this->deploymentConfig->get());
233233
$this->deploymentConfig->resetData();
234234
// second time to ensure loader will be invoked only once after reset

0 commit comments

Comments
 (0)