mirror of
https://github.com/nextcloud/server.git
synced 2026-03-14 22:53:43 -04:00
perf(federation): Only request root share info for checking availability
Otherwise this would request a full recursive dirctory listing while the result is never being used Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
parent
b2a8a95a47
commit
eef2cb855b
2 changed files with 13 additions and 9 deletions
|
|
@ -65,7 +65,7 @@ class ShareInfoController extends ApiController {
|
|||
* @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,28 +96,32 @@ 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) {
|
||||
if ($node instanceof File) {
|
||||
return $this->parseFile($node, $permissionMask);
|
||||
}
|
||||
return $this->parseFolder($node, $permissionMask);
|
||||
return $this->parseFolder($node, $permissionMask, $depth);
|
||||
}
|
||||
|
||||
private function parseFile(File $file, int $permissionMask) {
|
||||
return $this->format($file, $permissionMask);
|
||||
}
|
||||
|
||||
private function parseFolder(Folder $folder, int $permissionMask) {
|
||||
private function parseFolder(Folder $folder, int $permissionMask, int $depth) {
|
||||
$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;
|
||||
|
|
|
|||
6
apps/files_sharing/lib/External/Storage.php
vendored
6
apps/files_sharing/lib/External/Storage.php
vendored
|
|
@ -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,
|
||||
]);
|
||||
|
|
|
|||
Loading…
Reference in a new issue