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.
This commit is contained in:
+1
-1
@@ -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
|
||||
|
||||
@@ -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`:
|
||||
|
||||
@@ -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)
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
@@ -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[] = [
|
||||
|
||||
Reference in New Issue
Block a user