Skip to content

Commit

Permalink
Merge pull request #23822 from nextcloud/enh/parse_localse_only_once
Browse files Browse the repository at this point in the history
Only parse the locales ones
  • Loading branch information
rullzer authored Nov 2, 2020
2 parents 1080515 + 6e377a9 commit ff08b10
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions lib/private/L10N/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@

namespace OC\L10N;

use Ds\Set;
use OCP\IConfig;
use OCP\IRequest;
use OCP\IUser;
Expand All @@ -63,6 +64,11 @@ class Factory implements IFactory {
*/
protected $availableLanguages = [];

/**
* @var Set
*/
protected $localeCache;

/**
* @var array
*/
Expand Down Expand Up @@ -104,6 +110,7 @@ public function __construct(IConfig $config,
$this->request = $request;
$this->userSession = $userSession;
$this->serverRoot = $serverRoot;
$this->localeCache = new Set();
}

/**
Expand Down Expand Up @@ -391,12 +398,14 @@ public function localeExists($locale) {
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);
}

/**
Expand Down

0 comments on commit ff08b10

Please sign in to comment.