Skip to content

Commit a295159

Browse files
Merge pull request #18393 from kamil-tekiela/Remove-Session-cache-in-Relation
Remove session cache in relation
2 parents c7b92d2 + 05e7123 commit a295159

32 files changed

Lines changed: 130 additions & 305 deletions

libraries/classes/ConfigStorage/Relation.php

Lines changed: 6 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -57,39 +57,19 @@
5757
*/
5858
class Relation
5959
{
60-
/** @var RelationParameters[] $cache */
61-
private static array $cache = [];
60+
private static RelationParameters|null $cache = null;
6261

6362
public function __construct(public DatabaseInterface $dbi)
6463
{
6564
}
6665

6766
public function getRelationParameters(): RelationParameters
6867
{
69-
$server = $GLOBALS['server'];
70-
71-
if (isset(self::$cache[$server])) {
72-
return self::$cache[$server];
73-
}
74-
75-
if (! isset($_SESSION['relation']) || ! is_array($_SESSION['relation'])) {
76-
$_SESSION['relation'] = [];
68+
if (self::$cache === null) {
69+
self::$cache = RelationParameters::fromArray($this->checkRelationsParam());
7770
}
7871

79-
if (
80-
isset($_SESSION['relation'][$server]) && is_array($_SESSION['relation'][$server])
81-
&& isset($_SESSION['relation'][$server]['version'])
82-
&& $_SESSION['relation'][$server]['version'] === Version::VERSION
83-
) {
84-
self::$cache[$server] = RelationParameters::fromArray($_SESSION['relation'][$server]);
85-
86-
return self::$cache[$server];
87-
}
88-
89-
self::$cache[$server] = RelationParameters::fromArray($this->checkRelationsParam());
90-
$_SESSION['relation'][$server] = self::$cache[$server]->toArray();
91-
92-
return self::$cache[$server];
72+
return self::$cache;
9373
}
9474

9575
/**
@@ -1510,8 +1490,7 @@ public function createPmaDatabase(string $configurationStorageDbName): bool
15101490
// Re-build the cache to show the list of tables created or not
15111491
// This is the case when the DB could be created but no tables just after
15121492
// So just purge the cache and show the new configuration storage state
1513-
unset($_SESSION['relation'][$GLOBALS['server']]);
1514-
unset(self::$cache[$GLOBALS['server']]);
1493+
self::$cache = null;
15151494
$this->getRelationParameters();
15161495

15171496
return true;
@@ -1625,8 +1604,7 @@ public function fixPmaTables(string $db, bool $create = true): void
16251604

16261605
//NOTE: I am unsure why we do that, as it defeats the purpose of the session cache
16271606
// Unset the cache
1628-
unset($_SESSION['relation'][$GLOBALS['server']]);
1629-
unset(self::$cache[$GLOBALS['server']]);
1607+
self::$cache = null;
16301608
// Fill back the cache
16311609
$this->getRelationParameters();
16321610
}

libraries/classes/UserPreferences.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,10 +169,7 @@ public function save(array $configArray): bool|Message
169169
/**
170170
* When phpMyAdmin cached the configuration storage parameters, it checked if the database can be
171171
* accessed, so if it could not be accessed anymore, then the cache must be cleared as it's out of date.
172-
*
173-
* @psalm-suppress MixedArrayAssignment
174172
*/
175-
$_SESSION['relation'][$GLOBALS['server']] = [];
176173
$message->addMessage(Message::error(htmlspecialchars(
177174
__('The phpMyAdmin configuration storage database could not be accessed.'),
178175
)), '<br><br>');

phpstan-baseline.neon

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1527,7 +1527,7 @@ parameters:
15271527

15281528
-
15291529
message: "#^Cannot access offset mixed on mixed\\.$#"
1530-
count: 3
1530+
count: 1
15311531
path: libraries/classes/ConfigStorage/Relation.php
15321532

15331533
-
@@ -26750,11 +26750,6 @@ parameters:
2675026750
count: 4
2675126751
path: libraries/classes/UserPreferences.php
2675226752

26753-
-
26754-
message: "#^Cannot access offset mixed on mixed\\.$#"
26755-
count: 1
26756-
path: libraries/classes/UserPreferences.php
26757-
2675826753
-
2675926754
message: "#^Cannot access offset non\\-falsy\\-string on mixed\\.$#"
2676026755
count: 4
@@ -28000,6 +27995,11 @@ parameters:
2800027995
count: 1
2800127996
path: test/classes/Config/SettingsTest.php
2800227997

27998+
-
27999+
message: "#^Call to method PHPUnit\\\\Framework\\\\Assert\\:\\:assertArrayHasKey\\(\\) with arguments 'relation', array\\{version\\: string, user\\: string\\|null, db\\: string\\|null, bookmark\\: string\\|null, central_columns\\: string\\|null, column_info\\: string\\|null, designer_settings\\: string\\|null, export_templates\\: string\\|null, \\.\\.\\.\\} and 'The cache is…' will always evaluate to true\\.$#"
28000+
count: 3
28001+
path: test/classes/ConfigStorage/RelationTest.php
28002+
2800328003
-
2800428004
message: "#^Cannot access offset 'DisableIS' on mixed\\.$#"
2800528005
count: 2
@@ -28120,16 +28120,6 @@ parameters:
2812028120
count: 15
2812128121
path: test/classes/ConfigStorage/RelationTest.php
2812228122

28123-
-
28124-
message: "#^Cannot access offset mixed on mixed\\.$#"
28125-
count: 3
28126-
path: test/classes/ConfigStorage/RelationTest.php
28127-
28128-
-
28129-
message: "#^Parameter \\#1 \\$key of method PHPUnit\\\\Framework\\\\Assert\\:\\:assertArrayHasKey\\(\\) expects int\\|string, mixed given\\.$#"
28130-
count: 6
28131-
path: test/classes/ConfigStorage/RelationTest.php
28132-
2813328123
-
2813428124
message: "#^Cannot access offset 'NavigationWidth' on mixed\\.$#"
2813528125
count: 1

psalm-baseline.xml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -698,8 +698,6 @@
698698
<code><![CDATA[uksort($foreign, 'strnatcasecmp')]]></code>
699699
</MixedArgumentTypeCoercion>
700700
<MixedArrayAccess>
701-
<code><![CDATA[$_SESSION['relation'][$GLOBALS['server']]]]></code>
702-
<code><![CDATA[$_SESSION['relation'][$GLOBALS['server']]]]></code>
703701
<code><![CDATA[$column['COLUMN_NAME']]]></code>
704702
<code><![CDATA[$column['DATA_TYPE']]]></code>
705703
<code><![CDATA[$columns['table_name']]]></code>
@@ -13185,11 +13183,6 @@
1318513183
<DocblockTypeContradiction>
1318613184
<code>assertSame</code>
1318713185
</DocblockTypeContradiction>
13188-
<InvalidScalarArgument>
13189-
<code>$_SESSION</code>
13190-
<code>$_SESSION</code>
13191-
<code>$_SESSION</code>
13192-
</InvalidScalarArgument>
1319313186
<PossiblyUnusedMethod>
1319413187
<code>providerForTestRenameTable</code>
1319513188
</PossiblyUnusedMethod>

test/classes/AbstractTestCase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ protected function setUp(): void
8585
$this->setGlobalConfig();
8686
Cache::purge();
8787

88-
(new ReflectionProperty(Relation::class, 'cache'))->setValue(null, []);
88+
(new ReflectionProperty(Relation::class, 'cache'))->setValue(null, null);
8989
}
9090

9191
protected function loadContainerBuilder(): void

0 commit comments

Comments
 (0)