Skip to content

Commit 1fed799

Browse files
authored
Merge pull request #36452 from nextcloud/perf/share-availability-check
perf(federation): Only request root share info for checking availability
2 parents 7cff390 + 7e3ea01 commit 1fed799

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

apps/files_sharing/lib/Controller/ShareInfoController.php

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public function __construct(string $appName,
6565
* @param ?string $dir
6666
* @return JSONResponse
6767
*/
68-
public function info(string $t, ?string $password = null, ?string $dir = null) {
68+
public function info(string $t, ?string $password = null, ?string $dir = null, int $depth = -1): JSONResponse {
6969
try {
7070
$share = $this->shareManager->getShareByToken($t);
7171
} catch (ShareNotFound $e) {
@@ -96,34 +96,39 @@ public function info(string $t, ?string $password = null, ?string $dir = null) {
9696
}
9797
}
9898

99-
return new JSONResponse($this->parseNode($node, $permissionMask));
99+
return new JSONResponse($this->parseNode($node, $permissionMask, $depth));
100100
}
101101

102-
private function parseNode(Node $node, int $permissionMask) {
102+
private function parseNode(Node $node, int $permissionMask, int $depth): array {
103103
if ($node instanceof File) {
104104
return $this->parseFile($node, $permissionMask);
105105
}
106-
return $this->parseFolder($node, $permissionMask);
106+
/** @var Folder $node */
107+
return $this->parseFolder($node, $permissionMask, $depth);
107108
}
108109

109-
private function parseFile(File $file, int $permissionMask) {
110+
private function parseFile(File $file, int $permissionMask): array {
110111
return $this->format($file, $permissionMask);
111112
}
112113

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

117+
if ($depth === 0) {
118+
return $data;
119+
}
120+
116121
$data['children'] = [];
117122

118123
$nodes = $folder->getDirectoryListing();
119124
foreach ($nodes as $node) {
120-
$data['children'][] = $this->parseNode($node, $permissionMask);
125+
$data['children'][] = $this->parseNode($node, $permissionMask, $depth <= -1 ? -1 : $depth - 1);
121126
}
122127

123128
return $data;
124129
}
125130

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

129134
$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)