Skip to content

Commit 5c53fe7

Browse files
authored
Merge pull request #36557 from nextcloud/backport/36452/stable25
[stable25] perf(federation): Only request root share info for checking availability
2 parents e57d799 + c54deed commit 5c53fe7

2 files changed

Lines changed: 16 additions & 16 deletions

File tree

apps/files_sharing/lib/Controller/ShareInfoController.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,8 @@ public function __construct(string $appName,
5959
* @PublicPage
6060
* @NoCSRFRequired
6161
* @BruteForceProtection(action=shareinfo)
62-
*
63-
* @param string $t
64-
* @param null $password
65-
* @param null $dir
66-
* @return JSONResponse
6762
*/
68-
public function info($t, $password = null, $dir = null) {
63+
public function info(string $t, ?string $password = null, ?string $dir = null, int $depth = -1): JSONResponse {
6964
try {
7065
$share = $this->shareManager->getShareByToken($t);
7166
} catch (ShareNotFound $e) {
@@ -96,34 +91,39 @@ public function info($t, $password = null, $dir = null) {
9691
}
9792
}
9893

99-
return new JSONResponse($this->parseNode($node, $permissionMask));
94+
return new JSONResponse($this->parseNode($node, $permissionMask, $depth));
10095
}
10196

102-
private function parseNode(Node $node, int $permissionMask) {
97+
private function parseNode(Node $node, int $permissionMask, int $depth): array {
10398
if ($node instanceof File) {
10499
return $this->parseFile($node, $permissionMask);
105100
}
106-
return $this->parseFolder($node, $permissionMask);
101+
/** @var Folder $node */
102+
return $this->parseFolder($node, $permissionMask, $depth);
107103
}
108104

109-
private function parseFile(File $file, int $permissionMask) {
105+
private function parseFile(File $file, int $permissionMask): array {
110106
return $this->format($file, $permissionMask);
111107
}
112108

113-
private function parseFolder(Folder $folder, int $permissionMask) {
109+
private function parseFolder(Folder $folder, int $permissionMask, int $depth): array {
114110
$data = $this->format($folder, $permissionMask);
115111

112+
if ($depth === 0) {
113+
return $data;
114+
}
115+
116116
$data['children'] = [];
117117

118118
$nodes = $folder->getDirectoryListing();
119119
foreach ($nodes as $node) {
120-
$data['children'][] = $this->parseNode($node, $permissionMask);
120+
$data['children'][] = $this->parseNode($node, $permissionMask, $depth <= -1 ? -1 : $depth - 1);
121121
}
122122

123123
return $data;
124124
}
125125

126-
private function format(Node $node, int $permissionMask) {
126+
private function format(Node $node, int $permissionMask): array {
127127
$entry = [];
128128

129129
$entry['id'] = $node->getId();

apps/files_sharing/lib/External/Storage.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ public function test() {
214214
public function checkStorageAvailability() {
215215
// see if we can find out why the share is unavailable
216216
try {
217-
$this->getShareInfo();
217+
$this->getShareInfo(0);
218218
} catch (NotFoundException $e) {
219219
// a 404 can either mean that the share no longer exists or there is no Nextcloud on the remote
220220
if ($this->testRemote()) {
@@ -308,7 +308,7 @@ public function remoteIsOwnCloud(): bool {
308308
* @throws NotFoundException
309309
* @throws \Exception
310310
*/
311-
public function getShareInfo() {
311+
public function getShareInfo(int $depth = -1) {
312312
$remote = $this->getRemote();
313313
$token = $this->getToken();
314314
$password = $this->getPassword();
@@ -331,7 +331,7 @@ public function getShareInfo() {
331331
$client = \OC::$server->getHTTPClientService()->newClient();
332332
try {
333333
$response = $client->post($url, [
334-
'body' => ['password' => $password],
334+
'body' => ['password' => $password, 'depth' => $depth],
335335
'timeout' => 10,
336336
'connect_timeout' => 10,
337337
]);

0 commit comments

Comments
 (0)