Skip to content

Commit 304e2aa

Browse files
miaulalalaChristophWurst
authored andcommitted
Cache provisioning configs
Signed-off-by: Anna Larch <anna@nextcloud.com>
1 parent dd6cee6 commit 304e2aa

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

lib/Service/Provisioning/Manager.php

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
use OCA\Mail\Exception\ValidationException;
3535
use OCP\AppFramework\Db\DoesNotExistException;
3636
use OCP\AppFramework\Db\MultipleObjectsReturnedException;
37+
use OCP\ICacheFactory;
3738
use OCP\IUser;
3839
use OCP\IUserManager;
3940
use OCP\LDAP\ILDAPProvider;
@@ -67,14 +68,17 @@ class Manager {
6768
/** @var TagMapper */
6869
private $tagMapper;
6970

71+
private ICacheFactory $cacheFactory;
72+
7073
public function __construct(IUserManager $userManager,
7174
ProvisioningMapper $provisioningMapper,
7275
MailAccountMapper $mailAccountMapper,
7376
ICrypto $crypto,
7477
ILDAPProviderFactory $ldapProviderFactory,
7578
AliasMapper $aliasMapper,
7679
LoggerInterface $logger,
77-
TagMapper $tagMapper) {
80+
TagMapper $tagMapper,
81+
ICacheFactory $cacheFactory) {
7882
$this->userManager = $userManager;
7983
$this->provisioningMapper = $provisioningMapper;
8084
$this->mailAccountMapper = $mailAccountMapper;
@@ -83,14 +87,29 @@ public function __construct(IUserManager $userManager,
8387
$this->aliasMapper = $aliasMapper;
8488
$this->logger = $logger;
8589
$this->tagMapper = $tagMapper;
90+
$this->cacheFactory = $cacheFactory;
8691
}
8792

8893
public function getConfigById(int $provisioningId): ?Provisioning {
8994
return $this->provisioningMapper->get($provisioningId);
9095
}
9196

9297
public function getConfigs(): array {
93-
return $this->provisioningMapper->getAll();
98+
$cache = null;
99+
if ($this->cacheFactory->isLocalCacheAvailable()) {
100+
$cache = $this->cacheFactory->createLocal('provisionings');
101+
$cached = $cache->get('provisionings_all');
102+
if ($cached !== null) {
103+
return unserialize($cached, ['allowed_classes' => [Provisioning::class]]);
104+
}
105+
}
106+
107+
$provisionings = $this->provisioningMapper->getAll();
108+
// let's cache the provisionings for 5 minutes
109+
if ($this->cacheFactory->isLocalCacheAvailable()) {
110+
$cache->set('provisionings_all', serialize($provisionings), 60 * 5);
111+
}
112+
return $provisionings;
94113
}
95114

96115
public function provision(): int {

0 commit comments

Comments
 (0)