|
35 | 35 | use function __; |
36 | 36 | use function _pgettext; |
37 | 37 | use function array_filter; |
| 38 | +use function array_key_exists; |
38 | 39 | use function array_keys; |
39 | 40 | use function array_merge; |
40 | 41 | use function array_shift; |
@@ -249,6 +250,9 @@ class Results |
249 | 250 | /** @var Template */ |
250 | 251 | public $template; |
251 | 252 |
|
| 253 | + /** @var array<string, string|null> */ |
| 254 | + private $foreignKeyDisplayCache = []; |
| 255 | + |
252 | 256 | /** |
253 | 257 | * @param string $db the database name |
254 | 258 | * @param string $table the table name |
@@ -4363,22 +4367,25 @@ private function handleNonPrintableContents( |
4363 | 4367 | */ |
4364 | 4368 | private function getFromForeign(array $fieldInfo, string $whereComparison): ?string |
4365 | 4369 | { |
| 4370 | + $key = json_encode([$fieldInfo[0], $fieldInfo[1], $fieldInfo[2], $fieldInfo[3], $whereComparison]); |
| 4371 | + if (array_key_exists($key, $this->foreignKeyDisplayCache)) { |
| 4372 | + return $this->foreignKeyDisplayCache[$key]; |
| 4373 | + } |
| 4374 | + |
4366 | 4375 | $dispsql = 'SELECT ' . Util::backquote($fieldInfo[2]) |
4367 | 4376 | . ' FROM ' . Util::backquote($fieldInfo[3]) . '.' . Util::backquote($fieldInfo[0]) |
4368 | 4377 | . ' WHERE ' . Util::backquote($fieldInfo[1]) . $whereComparison |
4369 | 4378 | . ' LIMIT 1'; |
4370 | 4379 |
|
4371 | 4380 | $dispval = $this->dbi->fetchValue($dispsql); |
4372 | 4381 | if ($dispval === false) { |
4373 | | - return __('Link not found!'); |
4374 | | - } |
4375 | | - |
4376 | | - if ($dispval === null) { |
4377 | | - return null; |
| 4382 | + $dispval = __('Link not found!'); |
| 4383 | + } elseif ($dispval !== null) { |
| 4384 | + // Truncate values that are too long, see: #17902 |
| 4385 | + [, $dispval] = $this->getPartialText($dispval); |
4378 | 4386 | } |
4379 | 4387 |
|
4380 | | - // Truncate values that are too long, see: #17902 |
4381 | | - [, $dispval] = $this->getPartialText($dispval); |
| 4388 | + $this->foreignKeyDisplayCache[$key] = $dispval; |
4382 | 4389 |
|
4383 | 4390 | return $dispval; |
4384 | 4391 | } |
|
0 commit comments