]> source.dussan.org Git - nextcloud-server.git/commitdiff
Only parse the locales ones 23822/head
authorRoeland Jago Douma <roeland@famdouma.nl>
Sat, 31 Oct 2020 14:25:19 +0000 (15:25 +0100)
committerRoeland Jago Douma <roeland@famdouma.nl>
Sat, 31 Oct 2020 14:25:19 +0000 (15:25 +0100)
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>
lib/private/L10N/Factory.php

index 11f572fc3b045332c23c6297f368aed5e109c6c1..b807f5cb63f87de32b1d065bc7f1deddeb9d2109 100644 (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);
        }
 
        /**