aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/private/L10N/Factory.php13
-rw-r--r--lib/private/Server.php1
-rw-r--r--tests/lib/L10N/FactoryTest.php8
-rw-r--r--tests/lib/L10N/L10nTest.php4
4 files changed, 23 insertions, 3 deletions
diff --git a/lib/private/L10N/Factory.php b/lib/private/L10N/Factory.php
index 7fcfab37fa6..71910873db7 100644
--- a/lib/private/L10N/Factory.php
+++ b/lib/private/L10N/Factory.php
@@ -40,6 +40,8 @@ declare(strict_types=1);
namespace OC\L10N;
+use OCP\ICache;
+use OCP\ICacheFactory;
use OCP\IConfig;
use OCP\IRequest;
use OCP\IUser;
@@ -94,7 +96,9 @@ class Factory implements IFactory {
protected $request;
/** @var IUserSession */
- protected $userSession;
+ protected IUserSession $userSession;
+
+ private ICache $cache;
/** @var string */
protected $serverRoot;
@@ -109,11 +113,13 @@ class Factory implements IFactory {
IConfig $config,
IRequest $request,
IUserSession $userSession,
+ ICacheFactory $cacheFactory,
$serverRoot
) {
$this->config = $config;
$this->request = $request;
$this->userSession = $userSession;
+ $this->cache = $cacheFactory->createLocal('L10NFactory');
$this->serverRoot = $serverRoot;
}
@@ -338,6 +344,10 @@ class Factory implements IFactory {
$key = 'null';
}
+ if ($availableLanguages = $this->cache->get($key)) {
+ $this->availableLanguages[$key] = $availableLanguages;
+ }
+
// also works with null as key
if (!empty($this->availableLanguages[$key])) {
return $this->availableLanguages[$key];
@@ -374,6 +384,7 @@ class Factory implements IFactory {
}
$this->availableLanguages[$key] = $available;
+ $this->cache->set($key, $available, 60);
return $available;
}
diff --git a/lib/private/Server.php b/lib/private/Server.php
index 07e90843a98..d420b6fd11d 100644
--- a/lib/private/Server.php
+++ b/lib/private/Server.php
@@ -688,6 +688,7 @@ class Server extends ServerContainer implements IServerContainer {
$c->get(\OCP\IConfig::class),
$c->getRequest(),
$c->get(IUserSession::class),
+ $c->get(ICacheFactory::class),
\OC::$SERVERROOT
);
});
diff --git a/tests/lib/L10N/FactoryTest.php b/tests/lib/L10N/FactoryTest.php
index 4e01602a4f7..7af069cbff3 100644
--- a/tests/lib/L10N/FactoryTest.php
+++ b/tests/lib/L10N/FactoryTest.php
@@ -13,6 +13,7 @@ namespace Test\L10N;
use OC\L10N\Factory;
use OC\L10N\LanguageNotFoundException;
+use OCP\ICacheFactory;
use OCP\IConfig;
use OCP\IRequest;
use OCP\IUser;
@@ -32,6 +33,9 @@ class FactoryTest extends TestCase {
/** @var IUserSession|MockObject */
protected $userSession;
+ /** @var ICacheFactory|MockObject */
+ protected $cacheFactory;
+
/** @var string */
protected $serverRoot;
@@ -41,6 +45,7 @@ class FactoryTest extends TestCase {
$this->config = $this->createMock(IConfig::class);
$this->request = $this->createMock(IRequest::class);
$this->userSession = $this->createMock(IUserSession::class);
+ $this->cacheFactory = $this->createMock(ICacheFactory::class);
$this->serverRoot = \OC::$SERVERROOT;
}
@@ -64,13 +69,14 @@ class FactoryTest extends TestCase {
$this->config,
$this->request,
$this->userSession,
+ $this->cacheFactory,
$this->serverRoot,
])
->setMethods($methods)
->getMock();
}
- return new Factory($this->config, $this->request, $this->userSession, $this->serverRoot);
+ return new Factory($this->config, $this->request, $this->userSession, $this->cacheFactory, $this->serverRoot);
}
public function dataFindAvailableLanguages(): array {
diff --git a/tests/lib/L10N/L10nTest.php b/tests/lib/L10N/L10nTest.php
index f410c523c05..f224592432c 100644
--- a/tests/lib/L10N/L10nTest.php
+++ b/tests/lib/L10N/L10nTest.php
@@ -11,6 +11,7 @@ namespace Test\L10N;
use DateTime;
use OC\L10N\Factory;
use OC\L10N\L10N;
+use OCP\ICacheFactory;
use OCP\IConfig;
use OCP\IRequest;
use OCP\IUserSession;
@@ -32,7 +33,8 @@ class L10nTest extends TestCase {
$request = $this->createMock(IRequest::class);
/** @var IUserSession $userSession */
$userSession = $this->createMock(IUserSession::class);
- return new Factory($config, $request, $userSession, \OC::$SERVERROOT);
+ $cacheFactory = $this->createMock(ICacheFactory::class);
+ return new Factory($config, $request, $userSession, $cacheFactory, \OC::$SERVERROOT);
}
public function testSimpleTranslationWithTrailingColon(): void {