summaryrefslogtreecommitdiffstats
path: root/lib/private/L10N
diff options
context:
space:
mode:
authorRoeland Jago Douma <roeland@famdouma.nl>2020-10-31 15:25:19 +0100
committerRoeland Jago Douma <roeland@famdouma.nl>2020-10-31 15:25:19 +0100
commit6e377a9daf57b650d32ea34681d23bb5d67db01d (patch)
tree34f3bde8a284607be387f7a1fe17c2c58cb8dfe9 /lib/private/L10N
parent5396e98d2d9499f14a1c5abeb71e904642f90c26 (diff)
downloadnextcloud-server-6e377a9daf57b650d32ea34681d23bb5d67db01d.tar.gz
nextcloud-server-6e377a9daf57b650d32ea34681d23bb5d67db01d.zip
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>
Diffstat (limited to 'lib/private/L10N')
-rw-r--r--lib/private/L10N/Factory.php19
1 files changed, 14 insertions, 5 deletions
diff --git a/lib/private/L10N/Factory.php b/lib/private/L10N/Factory.php
index 11f572fc3b0..b807f5cb63f 100644
--- a/lib/private/L10N/Factory.php
+++ b/lib/private/L10N/Factory.php
@@ -37,6 +37,7 @@
namespace OC\L10N;
+use Ds\Set;
use OCP\IConfig;
use OCP\IRequest;
use OCP\IUser;
@@ -64,6 +65,11 @@ class Factory implements IFactory {
protected $availableLanguages = [];
/**
+ * @var Set
+ */
+ protected $localeCache;
+
+ /**
* @var array
*/
protected $availableLocales = [];
@@ -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);
}
/**