aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private/Support
diff options
context:
space:
mode:
authorRoeland Jago Douma <roeland@famdouma.nl>2020-07-08 19:38:26 +0200
committerRoeland Jago Douma <roeland@famdouma.nl>2020-07-09 12:21:06 +0200
commit725872c23a82a31026504e052cfff83bc4d6cceb (patch)
tree27db8a15169d77039a6724109188fae0ca263d9d /lib/private/Support
parent8f4d5334f4c392a5571c8f96292ae80fa9bbc177 (diff)
downloadnextcloud-server-725872c23a82a31026504e052cfff83bc4d6cceb.tar.gz
nextcloud-server-725872c23a82a31026504e052cfff83bc4d6cceb.zip
Make the subscription registry lazy
This will allow to do lazy registration here which should allow for loading less (or at least only when needed!). Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
Diffstat (limited to 'lib/private/Support')
-rw-r--r--lib/private/Support/Subscription/Registry.php46
1 files changed, 38 insertions, 8 deletions
diff --git a/lib/private/Support/Subscription/Registry.php b/lib/private/Support/Subscription/Registry.php
index f0d946a2911..9f5d78bebb2 100644
--- a/lib/private/Support/Subscription/Registry.php
+++ b/lib/private/Support/Subscription/Registry.php
@@ -27,7 +27,9 @@ declare(strict_types=1);
namespace OC\Support\Subscription;
+use OCP\AppFramework\QueryException;
use OCP\IConfig;
+use OCP\IServerContainer;
use OCP\Support\Subscription\Exception\AlreadyRegisteredException;
use OCP\Support\Subscription\IRegistry;
use OCP\Support\Subscription\ISubscription;
@@ -38,11 +40,30 @@ class Registry implements IRegistry {
/** @var ISubscription */
private $subscription = null;
+ /** @var string */
+ private $subscriptionService = null;
+
/** @var IConfig */
private $config;
- public function __construct(IConfig $config) {
+ /** @var IServerContainer */
+ private $container;
+
+ public function __construct(IConfig $config, IServerContainer $container) {
$this->config = $config;
+ $this->container = $container;
+ }
+
+ private function getSubscription(): ?ISubscription {
+ if ($this->subscription === null && $this->subscriptionService !== null) {
+ try {
+ $this->subscription = $this->container->query($this->subscriptionService);
+ } catch (QueryException $e) {
+ // Ignore this
+ }
+ }
+
+ return $this->subscription;
}
/**
@@ -55,20 +76,29 @@ class Registry implements IRegistry {
* @since 17.0.0
*/
public function register(ISubscription $subscription): void {
- if ($this->subscription !== null) {
+ if ($this->subscription !== null || $this->subscriptionService !== null) {
throw new AlreadyRegisteredException();
}
$this->subscription = $subscription;
}
+ public function registerService(string $subscriptionService): void {
+ if ($this->subscription !== null || $this->subscriptionService !== null) {
+ throw new AlreadyRegisteredException();
+ }
+
+ $this->subscriptionService = $subscriptionService;
+ }
+
+
/**
* Fetches the list of app IDs that are supported by the subscription
*
* @since 17.0.0
*/
public function delegateGetSupportedApps(): array {
- if ($this->subscription instanceof ISupportedApps) {
- return $this->subscription->getSupportedApps();
+ if ($this->getSubscription() instanceof ISupportedApps) {
+ return $this->getSubscription()->getSupportedApps();
}
return [];
}
@@ -84,8 +114,8 @@ class Registry implements IRegistry {
return true;
}
- if ($this->subscription instanceof ISubscription) {
- return $this->subscription->hasValidSubscription();
+ if ($this->getSubscription() instanceof ISubscription) {
+ return $this->getSubscription()->hasValidSubscription();
}
return false;
}
@@ -96,8 +126,8 @@ class Registry implements IRegistry {
* @since 17.0.0
*/
public function delegateHasExtendedSupport(): bool {
- if ($this->subscription instanceof ISubscription && method_exists($this->subscription, 'hasExtendedSupport')) {
- return $this->subscription->hasExtendedSupport();
+ if ($this->getSubscription() instanceof ISubscription && method_exists($this->subscription, 'hasExtendedSupport')) {
+ return $this->getSubscription()->hasExtendedSupport();
}
return false;
}