Skip to content

Commit 1d5d218

Browse files
authored
Merge pull request #52030 from nextcloud/backport/51946/stable31
[stable31] perf(cloud_federation_api): only provide capabilities if needed
2 parents 9821d3d + 9ffd7de commit 1d5d218

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)