Skip to content

Commit 9ffd7de

Browse files
susnuxbackportbot[bot]
authored andcommitted
perf(cloud_federation_api): only provide capabilities if needed
The capabilities can be quite expensive (e.g. on ARM board it takes 1s per request only for the capabilities). Also they are not used by the webui so they should not be included in initial state. Signed-off-by: Ferdinand Thiessen <[email protected]>
1 parent b8e8748 commit 9ffd7de

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

apps/cloud_federation_api/lib/Capabilities.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,14 @@
1212
use NCU\Security\Signature\Exceptions\SignatoryException;
1313
use OC\OCM\OCMSignatoryManager;
1414
use OCP\Capabilities\ICapability;
15+
use OCP\Capabilities\IInitialStateExcludedCapability;
1516
use OCP\IAppConfig;
1617
use OCP\IURLGenerator;
1718
use OCP\OCM\Exceptions\OCMArgumentException;
1819
use OCP\OCM\IOCMProvider;
1920
use Psr\Log\LoggerInterface;
2021

21-
class Capabilities implements ICapability {
22+
class Capabilities implements ICapability, IInitialStateExcludedCapability {
2223
public const API_VERSION = '1.1'; // informative, real version.
2324

2425
public function __construct(
@@ -54,15 +55,13 @@ public function __construct(
5455
*/
5556
public function getCapabilities() {
5657
$url = $this->urlGenerator->linkToRouteAbsolute('cloud_federation_api.requesthandlercontroller.addShare');
57-
58-
$this->provider->setEnabled(true);
59-
$this->provider->setApiVersion(self::API_VERSION);
60-
6158
$pos = strrpos($url, '/');
6259
if ($pos === false) {
63-
throw new OCMArgumentException('generated route should contains a slash character');
60+
throw new OCMArgumentException('generated route should contain a slash character');
6461
}
6562

63+
$this->provider->setEnabled(true);
64+
$this->provider->setApiVersion(self::API_VERSION);
6665
$this->provider->setEndPoint(substr($url, 0, $pos));
6766

6867
$resource = $this->provider->createNewResourceType();
@@ -87,6 +86,6 @@ public function getCapabilities() {
8786
$this->logger->warning('cannot generate local signatory', ['exception' => $e]);
8887
}
8988

90-
return ['ocm' => json_decode(json_encode($this->provider->jsonSerialize()), true)];
89+
return ['ocm' => $this->provider->jsonSerialize()];
9190
}
9291
}

0 commit comments

Comments
 (0)