summaryrefslogtreecommitdiffstats
path: root/apps/dav
diff options
context:
space:
mode:
authorRobin Appelman <robin@icewind.nl>2016-11-09 16:59:36 +0100
committerRobin Appelman <robin@icewind.nl>2016-11-09 17:04:44 +0100
commitd1291f7aeee53e78cffc19fa376c75084ca277a5 (patch)
treeb9b03c918879f5903bde4d232b06589a847252c6 /apps/dav
parent74024c8f28ed9c424fd1575afad290ad0de7e223 (diff)
downloadnextcloud-server-d1291f7aeee53e78cffc19fa376c75084ca277a5.tar.gz
nextcloud-server-d1291f7aeee53e78cffc19fa376c75084ca277a5.zip
remove unneeded getDirectoryContent when getting share types for a folder
Signed-off-by: Robin Appelman <robin@icewind.nl>
Diffstat (limited to 'apps/dav')
-rw-r--r--apps/dav/lib/Connector/Sabre/SharesPlugin.php34
1 files changed, 20 insertions, 14 deletions
diff --git a/apps/dav/lib/Connector/Sabre/SharesPlugin.php b/apps/dav/lib/Connector/Sabre/SharesPlugin.php
index 56d76e66184..33e79364758 100644
--- a/apps/dav/lib/Connector/Sabre/SharesPlugin.php
+++ b/apps/dav/lib/Connector/Sabre/SharesPlugin.php
@@ -67,6 +67,8 @@ class SharesPlugin extends \Sabre\DAV\ServerPlugin {
*/
private $cachedShareTypes;
+ private $cachedFolders = [];
+
/**
* @param \Sabre\DAV\Tree $tree tree
* @param IUserSession $userSession user session
@@ -143,24 +145,18 @@ class SharesPlugin extends \Sabre\DAV\ServerPlugin {
false
);
- $children = $node->getDirectoryListing();
+ $shareTypesByFileId = [];
- $values = array_map(function (\OCP\Files\Node $node) use ($shares) {
- /** @var IShare[] $shares */
- $shares = (isset($shares[$node->getId()])) ? $shares[$node->getId()] : [];
+ foreach($shares as $fileId => $sharesForFile) {
$types = array_map(function(IShare $share) {
return $share->getShareType();
- }, $shares);
+ }, $sharesForFile);
$types = array_unique($types);
sort($types);
- return $types;
- }, $children);
-
- $keys = array_map(function (\OCP\Files\Node $node) {
- return $node->getId();
- }, $children);
+ $shareTypesByFileId[$fileId] = $types;
+ }
- return array_combine($keys, $values);
+ return $shareTypesByFileId;
}
/**
@@ -185,6 +181,7 @@ class SharesPlugin extends \Sabre\DAV\ServerPlugin {
$folderNode = $this->userFolder->get($sabreNode->getPath());
$childShares = $this->getSharesTypesInFolder($folderNode);
+ $this->cachedFolders[] = $sabreNode->getPath();
$this->cachedShareTypes[$folderNode->getId()] = $this->getShareTypes($folderNode);
foreach ($childShares as $id => $shares) {
$this->cachedShareTypes[$id] = $shares;
@@ -195,8 +192,17 @@ class SharesPlugin extends \Sabre\DAV\ServerPlugin {
if (isset($this->cachedShareTypes[$sabreNode->getId()])) {
$shareTypes = $this->cachedShareTypes[$sabreNode->getId()];
} else {
- $node = $this->userFolder->get($sabreNode->getPath());
- $shareTypes = $this->getShareTypes($node);
+ list($parentPath,) = \Sabre\Uri\split($sabreNode->getPath());
+ if ($parentPath === '') {
+ $parentPath = '/';
+ }
+ // 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) {
+ $node = $this->userFolder->get($sabreNode->getPath());
+ $shareTypes = $this->getShareTypes($node);
+ } else {
+ return [];
+ }
}
return new ShareTypeList($shareTypes);