Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable25] perf(federation): Only request root share info for checking availability #36557

Merged
merged 2 commits into from
Feb 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions apps/files_sharing/lib/Controller/ShareInfoController.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,8 @@ public function __construct(string $appName,
* @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) {
Expand Down Expand Up @@ -96,34 +91,39 @@ public function info($t, $password = null, $dir = null) {
}
}

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();
Expand Down
6 changes: 3 additions & 3 deletions apps/files_sharing/lib/External/Storage.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ public function test() {
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()) {
Expand Down Expand Up @@ -308,7 +308,7 @@ public function remoteIsOwnCloud(): bool {
* @throws NotFoundException
* @throws \Exception
*/
public function getShareInfo() {
public function getShareInfo(int $depth = -1) {
$remote = $this->getRemote();
$token = $this->getToken();
$password = $this->getPassword();
Expand All @@ -331,7 +331,7 @@ public function getShareInfo() {
$client = \OC::$server->getHTTPClientService()->newClient();
try {
$response = $client->post($url, [
'body' => ['password' => $password],
'body' => ['password' => $password, 'depth' => $depth],
'timeout' => 10,
'connect_timeout' => 10,
]);
Expand Down