Skip to content

Commit 7630812

Browse files
Merge pull request #19541 from kamil-tekiela/SpecialSchemaLinks
Optimization: Memoize SpecialSchemaLinks
2 parents 6b6f423 + bac9bd4 commit 7630812

File tree

2 files changed

+45
-56
lines changed

2 files changed

+45
-56
lines changed

src/Config/SpecialSchemaLinks.php

Lines changed: 36 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -12,63 +12,55 @@
1212

1313
class SpecialSchemaLinks
1414
{
15+
/** @var array<'mysql'|'information_schema',
16+
* array<string,
17+
* array<string,
18+
* array{
19+
* 'link_param': string,
20+
* 'link_dependancy_params'?: array<
21+
* int,
22+
* array{'param_info': string, 'column_name': string}
23+
* >,
24+
* 'default_page': string
25+
* }
26+
* >
27+
* >
28+
* > */
29+
private static array $specialSchemaLinks = [];
30+
1531
/**
1632
* This array represent the details for generating links inside
1733
* special schemas like mysql, information_schema etc.
1834
* Major element represent a schema.
1935
* All the strings in this array represented in lower case
2036
*
21-
* Array structure ex:
22-
* array(
23-
* // Database name is the major element
24-
* 'mysql' => array(
25-
* // Table name
26-
* 'db' => array(
27-
* // Column name
28-
* 'user' => array(
29-
* // Main url param (can be an array where represent sql)
30-
* 'link_param' => 'username',
31-
* // Other url params
32-
* 'link_dependancy_params' => array(
33-
* 0 => array(
34-
* // URL parameter name
35-
* // (can be array where url param has static value)
36-
* 'param_info' => 'hostname',
37-
* // Column name related to url param
38-
* 'column_name' => 'host'
39-
* )
40-
* ),
41-
* // Page to link
42-
* 'default_page' => './' . Url::getFromRoute('/server/privileges')
43-
* )
44-
* )
45-
* )
46-
* );
37+
* @param 'mysql'|'information_schema' $database
4738
*
48-
* @return array<string,array<string,array<string,array<string,array<int,array<string,string>>|string>>>>
49-
* @phpstan-return array<
50-
* string, array<
51-
* string, array<
52-
* string,
53-
* array{
54-
* 'link_param': string,
55-
* 'link_dependancy_params'?: array<
56-
* int,
57-
* array{'param_info': string, 'column_name': string}
58-
* >,
59-
* 'default_page': string
60-
* }>
61-
* >
62-
* >
63-
* }
39+
* @return array{
40+
* 'link_param': string,
41+
* 'link_dependancy_params'?: array<
42+
* int,
43+
* array{'param_info': string, 'column_name': string}
44+
* >,
45+
* 'default_page': string
46+
* }|null
6447
*/
65-
public static function get(): array
48+
public static function get(string $database, string $table, string $column): array|null
49+
{
50+
if (self::$specialSchemaLinks === []) {
51+
self::setSpecialSchemaLinks();
52+
}
53+
54+
return self::$specialSchemaLinks[$database][$table][$column] ?? null;
55+
}
56+
57+
private static function setSpecialSchemaLinks(): void
6658
{
6759
$config = Config::getInstance();
6860
$defaultPageDatabase = './' . Url::getFromRoute($config->settings['DefaultTabDatabase']);
6961
$defaultPageTable = './' . Url::getFromRoute($config->settings['DefaultTabTable']);
7062

71-
return [
63+
self::$specialSchemaLinks = [
7264
'mysql' => [
7365
'columns_priv' => [
7466
'user' => [

src/Display/Results.php

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2084,8 +2084,6 @@ private function getRowValues(
20842084

20852085
$rowInfo = $this->getRowInfoForSpecialLinks($row);
20862086

2087-
// Load SpecialSchemaLinks for all rows
2088-
$specialSchemaLinks = SpecialSchemaLinks::get();
20892087
$relationParameters = $this->relation->getRelationParameters();
20902088

20912089
$columnCount = count($this->fieldsMeta);
@@ -2169,18 +2167,17 @@ private function getRowValues(
21692167
. '_' . $this->transformationInfo[$dbLower][$orgTable][$orgName]::getMIMESubtype();
21702168
}
21712169

2172-
// Check for the predefined fields need to show as link in schemas
2173-
if (isset($specialSchemaLinks[$dbLower][$tblLower][$nameLower])) {
2174-
$linkingUrl = $this->getSpecialLinkUrl(
2175-
$specialSchemaLinks[$dbLower][$tblLower][$nameLower],
2176-
$row[$i],
2177-
$rowInfo,
2178-
);
2179-
$transformationPlugin = new Text_Plain_Link();
2170+
if ($dbLower === 'mysql' || $dbLower === 'information_schema') {
2171+
// Check for the predefined fields need to show as link in schemas
2172+
$specialSchemaLink = SpecialSchemaLinks::get($dbLower, $tblLower, $nameLower);
2173+
if ($specialSchemaLink !== null) {
2174+
$linkingUrl = $this->getSpecialLinkUrl($specialSchemaLink, $row[$i], $rowInfo);
2175+
$transformationPlugin = new Text_Plain_Link();
21802176

2181-
$transformOptions = [0 => $linkingUrl, 2 => true];
2177+
$transformOptions = [0 => $linkingUrl, 2 => true];
21822178

2183-
$meta->internalMediaType = 'Text_Plain';
2179+
$meta->internalMediaType = 'Text_Plain';
2180+
}
21842181
}
21852182

21862183
$expressions = [];

0 commit comments

Comments
 (0)