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

Improve performance dav PROPFIND #31843

Merged
merged 4 commits into from
Apr 6, 2022
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
13 changes: 10 additions & 3 deletions apps/dav/lib/Connector/Sabre/Directory.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
use OCA\DAV\Connector\Sabre\Exception\Forbidden;
use OCA\DAV\Connector\Sabre\Exception\InvalidPath;
use OCP\Files\FileInfo;
use OCP\Files\Folder;
use OCP\Files\ForbiddenException;
use OCP\Files\InvalidPathException;
use OCP\Files\NotPermittedException;
Expand Down Expand Up @@ -144,7 +145,9 @@ public function createFile($name, $data = null) {
$info = $this->fileView->getFileInfo($this->path . '/' . $name);
if (!$info) {
// use a dummy FileInfo which is acceptable here since it will be refreshed after the put is complete
$info = new \OC\Files\FileInfo($path, null, null, [], null);
$info = new \OC\Files\FileInfo($path, null, null, [
'type' => FileInfo::TYPE_FILE
], null);
}
$node = new \OCA\DAV\Connector\Sabre\File($this->fileView, $info);

Expand Down Expand Up @@ -233,7 +236,7 @@ public function getChild($name, $info = null) {
throw new \Sabre\DAV\Exception\NotFound('File with name ' . $path . ' could not be located');
}

if ($info['mimetype'] === 'httpd/unix-directory') {
if ($info->getMimeType() === FileInfo::MIMETYPE_FOLDER) {
$node = new \OCA\DAV\Connector\Sabre\Directory($this->fileView, $info, $this->tree, $this->shareManager);
} else {
$node = new \OCA\DAV\Connector\Sabre\File($this->fileView, $info, $this->shareManager);
Expand Down Expand Up @@ -261,7 +264,7 @@ public function getChildren() {
// the caller believe that the collection itself does not exist
throw new Forbidden('No read permissions');
}
$folderContent = $this->fileView->getDirectoryContent($this->path);
$folderContent = $this->getNode()->getDirectoryListing();
} catch (LockedException $e) {
throw new Locked();
}
Expand Down Expand Up @@ -474,4 +477,8 @@ public function copyInto($targetName, $sourcePath, INode $sourceNode) {

return false;
}

public function getNode(): Folder {
return $this->node;
}
}
4 changes: 4 additions & 0 deletions apps/dav/lib/Connector/Sabre/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -753,4 +753,8 @@ protected function header($string) {
public function hash(string $type) {
return $this->fileView->hash($type, $this->path);
}

public function getNode(): \OCP\Files\File {
return $this->node;
}
}
25 changes: 25 additions & 0 deletions apps/dav/lib/Connector/Sabre/Node.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,12 @@
namespace OCA\DAV\Connector\Sabre;

use OC\Files\Mount\MoveableMount;
use OC\Files\Node\File;
use OC\Files\Node\Folder;
use OC\Files\View;
use OCA\DAV\Connector\Sabre\Exception\InvalidPath;
use OCP\Files\FileInfo;
use OCP\Files\IRootFolder;
use OCP\Files\StorageNotAvailableException;
use OCP\Share\IShare;
use OCP\Share\Exceptions\ShareNotFound;
Expand Down Expand Up @@ -75,6 +78,8 @@ abstract class Node implements \Sabre\DAV\INode {
*/
protected $shareManager;

protected \OCP\Files\Node $node;

/**
* Sets up the node, expects a full path name
*
Expand All @@ -91,10 +96,26 @@ public function __construct(View $view, FileInfo $info, IManager $shareManager =
} else {
$this->shareManager = \OC::$server->getShareManager();
}
if ($info instanceof Folder || $info instanceof File) {
$this->node = $info;
} else {
$root = \OC::$server->get(IRootFolder::class);
if ($info->getType() === FileInfo::TYPE_FOLDER) {
$this->node = new Folder($root, $view, $this->path, $info);
} else {
$this->node = new File($root, $view, $this->path, $info);
}
}
}

protected function refreshInfo() {
$this->info = $this->fileView->getFileInfo($this->path);
$root = \OC::$server->get(IRootFolder::class);
if ($this->info->getType() === FileInfo::TYPE_FOLDER) {
$this->node = new Folder($root, $this->fileView, $this->path, $this->info);
} else {
$this->node = new File($root, $this->fileView, $this->path, $this->info);
}
}

/**
Expand Down Expand Up @@ -403,6 +424,10 @@ public function getFileInfo() {
return $this->info;
}

public function getNode(): \OCP\Files\Node {
return $this->node;
}

protected function sanitizeMtime($mtimeFromRequest) {
return MtimeSanitizer::sanitizeMtime($mtimeFromRequest);
}
Expand Down
15 changes: 2 additions & 13 deletions apps/dav/lib/Connector/Sabre/SharesPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ private function getShares(DavNode $sabreNode): array {
// if we already cached the folder this file is in we know there are no shares for this file
if (array_search($parentPath, $this->cachedFolders) === false) {
try {
$node = $this->userFolder->get($sabreNode->getPath());
$node = $sabreNode->getNode();
} catch (NotFoundException $e) {
return [];
}
Expand Down Expand Up @@ -201,18 +201,7 @@ public function handleGetProperties(
!is_null($propFind->getStatus(self::SHAREES_PROPERTYNAME))
)
) {
try {
$folderNode = $this->userFolder->get($sabreNode->getPath());
} catch (NotFoundException $e) {
// If the folder can't be properly found just return
return;
}

if (!($folderNode instanceof Folder)) {
// Safety check
return;
}

$folderNode = $sabreNode->getNode();
$this->cachedFolders[] = $sabreNode->getPath();
$childShares = $this->getSharesFolder($folderNode);
foreach ($childShares as $id => $shares) {
Expand Down
36 changes: 22 additions & 14 deletions apps/dav/tests/unit/Connector/Sabre/DirectoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
namespace OCA\DAV\Tests\Unit\Connector\Sabre;

use OC\Files\FileInfo;
use OC\Files\Node\Node;
use OC\Files\Storage\Wrapper\Quota;
use OCA\DAV\Connector\Sabre\Directory;
use OCP\Files\ForbiddenException;
Expand Down Expand Up @@ -82,9 +83,12 @@ protected function setUp(): void {

$this->view = $this->createMock('OC\Files\View');
$this->info = $this->createMock('OC\Files\FileInfo');
$this->info->expects($this->any())
->method('isReadable')
$this->info->method('isReadable')
->willReturn(true);
$this->info->method('getType')
->willReturn(Node::TYPE_FOLDER);
$this->info->method('getName')
->willReturn("folder");
}

private function getDir($path = '/') {
Expand Down Expand Up @@ -186,17 +190,17 @@ public function testGetChildren() {
$info2 = $this->getMockBuilder(FileInfo::class)
->disableOriginalConstructor()
->getMock();
$info1->expects($this->any())
->method('getName')
$info1->method('getName')
->willReturn('first');
$info1->expects($this->any())
->method('getEtag')
$info1->method('getPath')
->willReturn('folder/first');
$info1->method('getEtag')
->willReturn('abc');
$info2->expects($this->any())
->method('getName')
$info2->method('getName')
->willReturn('second');
$info2->expects($this->any())
->method('getEtag')
$info2->method('getPath')
->willReturn('folder/second');
$info2->method('getEtag')
->willReturn('def');

$this->view->expects($this->once())
Expand Down Expand Up @@ -403,8 +407,12 @@ public function moveSuccessProvider() {
private function moveTest($source, $destination, $updatables, $deletables) {
$view = new TestViewDirectory($updatables, $deletables);

$sourceInfo = new FileInfo($source, null, null, [], null);
$targetInfo = new FileInfo(dirname($destination), null, null, [], null);
$sourceInfo = new FileInfo($source, null, null, [
'type' => FileInfo::TYPE_FOLDER,
], null);
$targetInfo = new FileInfo(dirname($destination), null, null, [
'type' => FileInfo::TYPE_FOLDER,
], null);

$sourceNode = new Directory($view, $sourceInfo);
$targetNode = $this->getMockBuilder(Directory::class)
Expand All @@ -429,8 +437,8 @@ public function testFailingMove() {

$view = new TestViewDirectory($updatables, $deletables);

$sourceInfo = new FileInfo($source, null, null, [], null);
$targetInfo = new FileInfo(dirname($destination), null, null, [], null);
$sourceInfo = new FileInfo($source, null, null, ['type' => FileInfo::TYPE_FOLDER], null);
$targetInfo = new FileInfo(dirname($destination), null, null, ['type' => FileInfo::TYPE_FOLDER], null);

$sourceNode = new Directory($view, $sourceInfo);
$targetNode = $this->getMockBuilder(Directory::class)
Expand Down
Loading