From 22e87e12ad7479b22b27f62f940c33a05659955b Mon Sep 17 00:00:00 2001 From: Dillard Blom Date: Wed, 30 Sep 2026 13:17:37 +0200 Subject: [PATCH] fix(config): only cache category names in the languages in use The cache held the category names in all 96 app store languages (about 49 KB), while an instance typically uses one or two. Keep only English, the default language and the languages users have set, as the two-letter codes the lookup uses; on a Dutch instance this is about 1.3 KB. A user who switches to a language that is not cached yet sees English names until the cache is refreshed after a week, or right away when an admin saves the settings. The README mentions this. --- CHANGELOG.md | 2 +- README.md | 2 ++ lib/AppInfo/Application.php | 4 +++- lib/Service/CategoryRepository.php | 25 ++++++++++++++++++++++++- 4 files changed, 30 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5aff943..75ad263 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ### Fixed -- fix(config): store the app store category cache lazily with only the names, refresh it weekly and when the settings are saved, and load it only when categories are used +- fix(config): store the app store category cache lazily with only the names in the languages in use, refresh it weekly and when the settings are saved, and load it only when categories are used - fix(admin): save all settings in one request so changes are not lost after the page reloads ## 6.2.0 diff --git a/README.md b/README.md index 3cb739f..e46bc5c 100644 --- a/README.md +++ b/README.md @@ -49,6 +49,8 @@ Users can disable the menu using the page of personal settings. Use the shortcut `Ctrl`+`o` to open and to hide the side menu. Use `tab` to navigate. +The names of the app store categories are cached for a week, only in the languages that are in use on the instance (and English). If a user switches to a new language and sees English category names, save the settings on the administration page to refresh the cache right away. + ### Use first top menu app as default app You can easily let Custom Menu redirect to the first app in the top menu by changing the following parameter in your `config/config.php`: diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index 2f6b936..380d04f 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -12,6 +12,7 @@ use OCA\SideMenu\Service\AppRepository; use OCA\SideMenu\Service\CategoryRepository; use OCA\SideMenu\Service\Color; use OCA\SideMenu\Service\ConfigProxy; +use OCA\SideMenu\Service\LangRepository; use OCA\Theming\ThemingDefaults; use OCP\AppFramework\App; use OCP\AppFramework\Bootstrap\IBootContext; @@ -60,7 +61,8 @@ class Application extends App implements IBootstrap $c->get(IFactory::class), $c->get(IUserSession::class), $c->get(IAppConfig::class), - $c->get(ITimeFactory::class) + $c->get(ITimeFactory::class), + $c->get(LangRepository::class) ); }); diff --git a/lib/Service/CategoryRepository.php b/lib/Service/CategoryRepository.php index d79dbcd..76af1fb 100644 --- a/lib/Service/CategoryRepository.php +++ b/lib/Service/CategoryRepository.php @@ -32,6 +32,7 @@ class CategoryRepository protected IUserSession $userSession, protected IAppConfig $appConfig, protected ITimeFactory $timeFactory, + protected LangRepository $langRepository, ) { } @@ -96,6 +97,25 @@ class CategoryRepository $this->appConfig->deleteKey(Application::APP_ID, self::CACHE_KEY); } + /** + * The languages to keep in the cache: English as fallback, the + * default language and the languages of the users, as two-letter + * codes like getOrderedCategories() looks them up. A user who picks + * a new language sees English names until the cache is refreshed, + * which saving the settings does right away. + */ + protected function getCachedLangs(): array + { + $langs = $this->langRepository->getUsedLangs(); + $langs[] = (string) $this->iConfig->getSystemValue('default_language', 'en'); + $langs[] = (string) $this->iConfig->getSystemValue('force_language', 'en'); + + return array_values(array_unique(array_filter(array_map( + static fn (string $lang) => strtolower(substr($lang, 0, 2)), + array_merge(['en'], $langs) + )))); + } + /** * Returns the app store categories with only their names, from a * cache that is stored lazily: it holds the names in every language, @@ -109,13 +129,16 @@ class CategoryRepository return $cache['categories']; } + $langs = $this->getCachedLangs(); $categories = []; foreach ($this->categoryFetcher->get() as $category) { $names = []; foreach ($category['translations'] ?? [] as $lang => $translation) { - $names[$lang] = ['name' => $translation['name'] ?? '']; + if (in_array($lang, $langs, true)) { + $names[$lang] = ['name' => $translation['name'] ?? '']; + } } $categories[] = [