summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorblizzz <blizzz@arthur-schiwon.de>2023-02-07 18:57:10 +0100
committerGitHub <noreply@github.com>2023-02-07 18:57:10 +0100
commitdc737047ce1229a076b2e3e9ef7d1f96f74d06e6 (patch)
treee50ee47f6d8fc9e67b046b71bdd01bff8e205cac
parent7c6a41488d2995f9af4b844dda64b53ba02904c3 (diff)
parenta5a5a78ae19b48c773619e98be3990154ad0c9cc (diff)
downloadnextcloud-server-dc737047ce1229a076b2e3e9ef7d1f96f74d06e6.tar.gz
nextcloud-server-dc737047ce1229a076b2e3e9ef7d1f96f74d06e6.zip
Merge pull request #36558 from nextcloud/backport/36557/stable24
[stable24] perf(federation): Only request root share info for checking availability
-rw-r--r--apps/files_sharing/lib/Controller/ShareInfoController.php26
-rw-r--r--apps/files_sharing/lib/External/Storage.php6
2 files changed, 16 insertions, 16 deletions
diff --git a/apps/files_sharing/lib/Controller/ShareInfoController.php b/apps/files_sharing/lib/Controller/ShareInfoController.php
index 429eb91bc92..0e2dd1667e1 100644
--- a/apps/files_sharing/lib/Controller/ShareInfoController.php
+++ b/apps/files_sharing/lib/Controller/ShareInfoController.php
@@ -59,13 +59,8 @@ class ShareInfoController extends ApiController {
* @PublicPage
* @NoCSRFRequired
* @BruteForceProtection(action=shareinfo)
- *
- * @param string $t
- * @param null $password
- * @param null $dir
- * @return JSONResponse
*/
- public function info($t, $password = null, $dir = null) {
+ public function info(string $t, ?string $password = null, ?string $dir = null, int $depth = -1): JSONResponse {
try {
$share = $this->shareManager->getShareByToken($t);
} catch (ShareNotFound $e) {
@@ -96,34 +91,39 @@ class ShareInfoController extends ApiController {
}
}
- return new JSONResponse($this->parseNode($node, $permissionMask));
+ return new JSONResponse($this->parseNode($node, $permissionMask, $depth));
}
- private function parseNode(Node $node, int $permissionMask) {
+ private function parseNode(Node $node, int $permissionMask, int $depth): array {
if ($node instanceof File) {
return $this->parseFile($node, $permissionMask);
}
- return $this->parseFolder($node, $permissionMask);
+ /** @var Folder $node */
+ return $this->parseFolder($node, $permissionMask, $depth);
}
- private function parseFile(File $file, int $permissionMask) {
+ private function parseFile(File $file, int $permissionMask): array {
return $this->format($file, $permissionMask);
}
- private function parseFolder(Folder $folder, int $permissionMask) {
+ private function parseFolder(Folder $folder, int $permissionMask, int $depth): array {
$data = $this->format($folder, $permissionMask);
+ if ($depth === 0) {
+ return $data;
+ }
+
$data['children'] = [];
$nodes = $folder->getDirectoryListing();
foreach ($nodes as $node) {
- $data['children'][] = $this->parseNode($node, $permissionMask);
+ $data['children'][] = $this->parseNode($node, $permissionMask, $depth <= -1 ? -1 : $depth - 1);
}
return $data;
}
- private function format(Node $node, int $permissionMask) {
+ private function format(Node $node, int $permissionMask): array {
$entry = [];
$entry['id'] = $node->getId();
diff --git a/apps/files_sharing/lib/External/Storage.php b/apps/files_sharing/lib/External/Storage.php
index 296e7ddf85b..5904727a141 100644
--- a/apps/files_sharing/lib/External/Storage.php
+++ b/apps/files_sharing/lib/External/Storage.php
@@ -214,7 +214,7 @@ class Storage extends DAV implements ISharedStorage, IDisableEncryptionStorage,
public function checkStorageAvailability() {
// see if we can find out why the share is unavailable
try {
- $this->getShareInfo();
+ $this->getShareInfo(0);
} catch (NotFoundException $e) {
// a 404 can either mean that the share no longer exists or there is no Nextcloud on the remote
if ($this->testRemote()) {
@@ -308,7 +308,7 @@ class Storage extends DAV implements ISharedStorage, IDisableEncryptionStorage,
* @throws NotFoundException
* @throws \Exception
*/
- public function getShareInfo() {
+ public function getShareInfo(int $depth = -1) {
$remote = $this->getRemote();
$token = $this->getToken();
$password = $this->getPassword();
@@ -331,7 +331,7 @@ class Storage extends DAV implements ISharedStorage, IDisableEncryptionStorage,
$client = \OC::$server->getHTTPClientService()->newClient();
try {
$response = $client->post($url, [
- 'body' => ['password' => $password],
+ 'body' => ['password' => $password, 'depth' => $depth],
'timeout' => 10,
'connect_timeout' => 10,
]);