Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions lib/Service/Provisioning/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
use OCA\Mail\Exception\ValidationException;
use OCP\AppFramework\Db\DoesNotExistException;
use OCP\AppFramework\Db\MultipleObjectsReturnedException;
use OCP\ICacheFactory;
use OCP\IUser;
use OCP\IUserManager;
use OCP\LDAP\ILDAPProvider;
Expand Down Expand Up @@ -67,14 +68,18 @@ class Manager {
/** @var TagMapper */
private $tagMapper;

/** @var ICacheFactory */
private $cacheFactory;

public function __construct(IUserManager $userManager,
ProvisioningMapper $provisioningMapper,
MailAccountMapper $mailAccountMapper,
ICrypto $crypto,
ILDAPProviderFactory $ldapProviderFactory,
AliasMapper $aliasMapper,
LoggerInterface $logger,
TagMapper $tagMapper) {
TagMapper $tagMapper,
ICacheFactory $cacheFactory) {
$this->userManager = $userManager;
$this->provisioningMapper = $provisioningMapper;
$this->mailAccountMapper = $mailAccountMapper;
Expand All @@ -83,14 +88,29 @@ public function __construct(IUserManager $userManager,
$this->aliasMapper = $aliasMapper;
$this->logger = $logger;
$this->tagMapper = $tagMapper;
$this->cacheFactory = $cacheFactory;
}

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

public function getConfigs(): array {
return $this->provisioningMapper->getAll();
$cache = null;
if ($this->cacheFactory->isLocalCacheAvailable()) {
$cache = $this->cacheFactory->createLocal('provisionings');
$cached = $cache->get('provisionings_all');
if ($cached !== null) {
return unserialize($cached, ['allowed_classes' => [Provisioning::class]]);
}
}

$provisionings = $this->provisioningMapper->getAll();
// let's cache the provisionings for 5 minutes
if ($this->cacheFactory->isLocalCacheAvailable()) {
$cache->set('provisionings_all', serialize($provisionings), 60 * 5);
}
return $provisionings;
}

public function provision(): int {
Expand Down