Skip to content

Commit 2877423

Browse files
committed
Merge branch 'refs/heads/6.2-overhaul-caching' into 6.2-tolerant-cache
2 parents 017fa57 + 0f563ea commit 2877423

File tree

8 files changed

+52
-58
lines changed

8 files changed

+52
-58
lines changed

wcfsetup/install/files/lib/system/cache/builder/AbstractLegacyCacheBuilder.class.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,19 @@
99
/**
1010
* Provides a backwards compatible interface for ICacheBuilder classes that have been migrated to the eager or tolerant cache implementations.
1111
*
12-
* @author Olaf Braun
13-
* @copyright 2001-2025 WoltLab GmbH
14-
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
12+
* @author Olaf Braun
13+
* @copyright 2001-2025 WoltLab GmbH
14+
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
1515
*
16-
* @since 6.2
17-
* @deprecated 6.2
16+
* @since 6.2
17+
* @deprecated 6.2
1818
*/
1919
abstract class AbstractLegacyCacheBuilder extends SingletonFactory implements ICacheBuilder
2020
{
21-
protected array $cache = [];
21+
/**
22+
* @var array<string, array<string|int, mixed>>
23+
*/
24+
private array $cache = [];
2225

2326
#[\Override]
2427
public function getData(array $parameters = [], $arrayIndex = '')

wcfsetup/install/files/lib/system/cache/builder/CoreObjectCacheBuilder.class.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
/**
88
* Caches the core objects.
99
*
10-
* @author Alexander Ebert
11-
* @copyright 2001-2019 WoltLab GmbH
12-
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
10+
* @author Olaf Braun, Alexander Ebert
11+
* @copyright 2001-2025 WoltLab GmbH
12+
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
1313
*
14-
* @deprecated 6.2 use `CoreObjectCache` instead
14+
* @deprecated 6.2 use `CoreObjectCache` instead
1515
*/
1616
class CoreObjectCacheBuilder extends AbstractLegacyCacheBuilder
1717
{

wcfsetup/install/files/lib/system/cache/builder/LanguageCacheBuilder.class.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
/**
88
* Caches languages and the id of the default language.
99
*
10-
* @author Olaf Braun, Marcel Werk
11-
* @copyright 2001-2025 WoltLab GmbH
12-
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
10+
* @author Olaf Braun, Marcel Werk
11+
* @copyright 2001-2025 WoltLab GmbH
12+
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
1313
*
14-
* @deprecated 6.2 use `LanguageCache` instead
14+
* @deprecated 6.2 use `LanguageCache` instead
1515
*/
1616
class LanguageCacheBuilder extends AbstractLegacyCacheBuilder
1717
{

wcfsetup/install/files/lib/system/cache/eager/AbstractEagerCache.class.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
use wcf\system\cache\CacheHandler;
66

77
/**
8-
* @author Olaf Braun
9-
* @copyright 2001-2025 WoltLab GmbH
10-
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
11-
* @since 6.2
8+
* @author Olaf Braun
9+
* @copyright 2001-2025 WoltLab GmbH
10+
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
11+
* @since 6.2
1212
*
1313
* @template T of array|object
1414
*/
@@ -25,7 +25,7 @@ abstract class AbstractEagerCache
2525
*
2626
* @return T
2727
*/
28-
final public function getCache(): array | object
28+
final public function getCache(): array|object
2929
{
3030
$key = $this->getCacheKey();
3131

@@ -97,5 +97,5 @@ final public function rebuild(): void
9797
*
9898
* @return T
9999
*/
100-
abstract protected function getCacheData(): array | object;
100+
abstract protected function getCacheData(): array|object;
101101
}

wcfsetup/install/files/lib/system/cache/eager/CoreObjectCache.class.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
/**
99
* Eager cache implementation for core objects.
1010
*
11-
* @author Olaf Braun
12-
* @copyright 2001-2025 WoltLab GmbH
13-
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
14-
* @since 6.2
11+
* @author Olaf Braun
12+
* @copyright 2001-2025 WoltLab GmbH
13+
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
14+
* @since 6.2
1515
*
1616
* @extends AbstractEagerCache<array<string, class-string<SingletonFactory>>>
1717
*/

wcfsetup/install/files/lib/system/cache/eager/LanguageCache.class.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,14 @@
66
use wcf\data\language\category\LanguageCategoryList;
77
use wcf\data\language\LanguageList;
88
use wcf\system\cache\eager\data\LanguageCacheData;
9-
use wcf\system\exception\SystemException;
109

1110
/**
1211
* Eager cache implementation for languages.
1312
*
14-
* @author Olaf Braun
15-
* @copyright 2001-2025 WoltLab GmbH
16-
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
17-
* @since 6.2
13+
* @author Olaf Braun
14+
* @copyright 2001-2025 WoltLab GmbH
15+
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
16+
* @since 6.2
1817
*
1918
* @extends AbstractEagerCache<LanguageCacheData>
2019
*/
@@ -59,7 +58,7 @@ protected function getCacheData(): LanguageCacheData
5958
}
6059

6160
if (!isset($languages[$default])) {
62-
throw new SystemException('No default language defined!');
61+
throw new \RuntimeException('No default language defined!');
6362
}
6463

6564
return new LanguageCacheData(

wcfsetup/install/files/lib/system/cache/eager/data/LanguageCacheData.class.php

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
/**
99
* Language cache data structure.
1010
*
11-
* @author Olaf Braun
12-
* @copyright 2001-2025 WoltLab GmbH
13-
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
14-
* @since 6.2
11+
* @author Olaf Braun
12+
* @copyright 2001-2025 WoltLab GmbH
13+
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
14+
* @since 6.2
1515
*/
1616
final class LanguageCacheData
1717
{
@@ -50,36 +50,33 @@ public function getLanguage(int $languageID): ?Language
5050
/**
5151
* Returns the language category with the given category name.
5252
*/
53-
public function getLanguageCategory(string $categoryName): ?LanguageCategory
53+
public function getCategory(string $categoryName): ?LanguageCategory
5454
{
5555
return $this->categories[$categoryName] ?? null;
5656
}
5757

5858
/**
5959
* Returns the language category with the given category id.
6060
*/
61-
public function getLanguageCategoryByID(int $languageCategoryID): ?LanguageCategory
61+
public function getCategoryByID(int $languageCategoryID): ?LanguageCategory
6262
{
6363
$categoryName = $this->categoryIDs[$languageCategoryID] ?? null;
6464
if ($categoryName === null) {
6565
return null;
6666
}
6767

68-
return $this->getLanguageCategory($categoryName);
68+
return $this->getCategory($categoryName);
6969
}
7070

71-
/**
72-
* Returns `true` if the language category with the given category name exists.
73-
*/
74-
public function languageCategoryExists(string $categoryName): bool
71+
public function hasCategory(string $categoryName): bool
7572
{
7673
return \array_key_exists($categoryName, $this->categories);
7774
}
7875

7976
/**
8077
* Return all content languages.
8178
*
82-
* @return list<Language>
79+
* @return array<int, Language>
8380
*/
8481
public function getContentLanguages(): array
8582
{
@@ -96,10 +93,7 @@ public function getContentLanguages(): array
9693
*/
9794
public function getContentLanguageIDs(): array
9895
{
99-
return \array_map(
100-
static fn(Language $language) => $language->languageID,
101-
$this->getContentLanguages()
102-
);
96+
return \array_keys($this->getContentLanguages());
10397
}
10498

10599
/**

wcfsetup/install/files/lib/system/language/LanguageFactory.class.php

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,15 @@
99
use wcf\data\language\LanguageEditor;
1010
use wcf\system\cache\eager\data\LanguageCacheData;
1111
use wcf\system\cache\eager\LanguageCache;
12-
use wcf\system\exception\SystemException;
1312
use wcf\system\SingletonFactory;
1413
use wcf\system\template\TemplateScriptingCompiler;
1514
use wcf\system\WCF;
1615

1716
/**
1817
* Handles language related functions.
1918
*
20-
* @author Alexander Ebert
21-
* @copyright 2001-2019 WoltLab GmbH
19+
* @author Olaf Braun, Alexander Ebert
20+
* @copyright 2001-2025 WoltLab GmbH
2221
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
2322
*/
2423
class LanguageFactory extends SingletonFactory
@@ -73,42 +72,41 @@ public function getUserLanguage(?int $languageID = null): Language
7372
*/
7473
public function getLanguageByCode(string $languageCode): ?Language
7574
{
76-
$language = $this->getLanguageByCode($languageCode);
77-
if ($language === null) {
75+
if ($this->cache->codes === []) {
7876
// called within WCFSetup
7977
$sql = "SELECT *
8078
FROM wcf1_language
8179
WHERE languageCode = ?";
8280
$statement = WCF::getDB()->prepare($sql);
8381
$statement->execute([$languageCode]);
84-
$language = $statement->fetchObject(Language::class);
82+
return $statement->fetchObject(Language::class);
83+
} else {
84+
return $this->getLanguageByCode($languageCode);
8585
}
86-
87-
return $language;
8886
}
8987

9088
/**
9189
* Returns true if the language category with the given name exists.
9290
*/
9391
public function isValidCategory(string $categoryName): bool
9492
{
95-
return $this->cache->languageCategoryExists($categoryName);
93+
return $this->cache->hasCategory($categoryName);
9694
}
9795

9896
/**
9997
* Returns the language category with the given name.
10098
*/
10199
public function getCategory(string $categoryName): ?LanguageCategory
102100
{
103-
return $this->cache->getLanguageCategory($categoryName);
101+
return $this->cache->getCategory($categoryName);
104102
}
105103

106104
/**
107105
* Returns language category by id.
108106
*/
109107
public function getCategoryByID(int $languageCategoryID): ?LanguageCategory
110108
{
111-
return $this->cache->getLanguageCategoryByID($languageCategoryID);
109+
return $this->cache->getCategoryByID($languageCategoryID);
112110
}
113111

114112
/**
@@ -138,7 +136,7 @@ protected function findPreferredLanguage(): int
138136
}
139137
}
140138

141-
throw new SystemException("No language found for language code '{$languageCode}'");
139+
throw new \RuntimeException("No language found for language code '{$languageCode}'");
142140
}
143141

144142
/**

0 commit comments

Comments
 (0)