]> source.dussan.org Git - nextcloud-server.git/commitdiff
remove unneeded getDirectoryContent when getting share types for a folder
authorRobin Appelman <robin@icewind.nl>
Wed, 9 Nov 2016 15:59:36 +0000 (16:59 +0100)
committerRobin Appelman <robin@icewind.nl>
Wed, 9 Nov 2016 16:04:44 +0000 (17:04 +0100)
Signed-off-by: Robin Appelman <robin@icewind.nl>
apps/dav/lib/Connector/Sabre/SharesPlugin.php

index 56d76e661846955d7a2cb71151edd2b564b9870f..33e793647583fa602026a16d6489c796a2593ed5 100644 (file)
@@ -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);