Only parse the locales ones

Before we'd go over the entire list for each translation (so each app)
we'd use translation for. This means we'd also go over thise locale list
(currently containing 750 entries) * apps so often this added up to ~20k
calls.

now we just dump the locales in a set once and then check if the entry
is there.

Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
This commit is contained in:
Roeland Jago Douma 2020-10-31 15:25:19 +01:00
parent 5396e98d2d
commit 6e377a9daf
No known key found for this signature in database
GPG Key ID: F941078878347C0C
1 changed files with 14 additions and 5 deletions

View File

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