Merge pull request #23822 from nextcloud/enh/parse_localse_only_once

Only parse the locales ones
This commit is contained in:
Roeland Jago Douma 2020-11-02 12:24:38 +01:00 committed by GitHub
commit ff08b10a89
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 14 additions and 5 deletions

View File

@ -37,6 +37,7 @@
namespace OC\L10N;
use Ds\Set;
use OCP\IConfig;
use OCP\IRequest;
use OCP\IUser;
@ -63,6 +64,11 @@ class Factory implements IFactory {
*/
protected $availableLanguages = [];
/**
* @var Set
*/
protected $localeCache;
/**
* @var array
*/
@ -104,6 +110,7 @@ class Factory implements IFactory {
$this->request = $request;
$this->userSession = $userSession;
$this->serverRoot = $serverRoot;
$this->localeCache = new Set();
}
/**
@ -391,12 +398,14 @@ class Factory implements IFactory {
return true;
}
$locales = $this->findAvailableLocales();
$userLocale = array_filter($locales, function ($value) use ($locale) {
return $locale === $value['code'];
});
if ($this->localeCache->isEmpty()) {
$locales = $this->findAvailableLocales();
foreach ($locales as $l) {
$this->localeCache->add($l['code']);
}
}
return !empty($userLocale);
return $this->localeCache->contains($locale);
}
/**