summaryrefslogtreecommitdiffstats
path: root/apps/dav
diff options
context:
space:
mode:
authorRobin Appelman <icewind@owncloud.com>2016-06-18 22:04:56 +0200
committerRoeland Jago Douma <roeland@famdouma.nl>2016-10-31 15:55:40 +0100
commit3692769b0a0713fa9e3976692736da76707986c5 (patch)
tree7749b3fcc18a8027301635519794a44b9bdc683e /apps/dav
parent357a823457397d3e93ec8cd4dc01fb6859eb0049 (diff)
downloadnextcloud-server-3692769b0a0713fa9e3976692736da76707986c5.tar.gz
nextcloud-server-3692769b0a0713fa9e3976692736da76707986c5.zip
Add getShareTypesInFolder to optimize folder listening
Signed-off-by: Robin Appelman <icewind@owncloud.com>
Diffstat (limited to 'apps/dav')
-rw-r--r--apps/dav/lib/Connector/Sabre/SharesPlugin.php32
-rw-r--r--apps/dav/tests/unit/Connector/Sabre/SharesPluginTest.php19
2 files changed, 47 insertions, 4 deletions
diff --git a/apps/dav/lib/Connector/Sabre/SharesPlugin.php b/apps/dav/lib/Connector/Sabre/SharesPlugin.php
index cd58f050dda..ebb7fefff33 100644
--- a/apps/dav/lib/Connector/Sabre/SharesPlugin.php
+++ b/apps/dav/lib/Connector/Sabre/SharesPlugin.php
@@ -136,6 +136,30 @@ class SharesPlugin extends \Sabre\DAV\ServerPlugin {
return $shareTypes;
}
+ private function getSharesTypesInFolder(\OCP\Files\Folder $node) {
+ $shares = $this->shareManager->getSharesInFolder(
+ $this->userId,
+ $node,
+ false
+ );
+
+ $children = $node->getDirectoryListing();
+
+ $values = array_map(function (\OCP\Files\Node $node) use ($shares) {
+ /** @var IShare[] $shares */
+ $shares = (isset($shares[$node->getId()])) ? $shares[$node->getId()] : [];
+ return array_map(function(IShare $share) {
+ return $share->getShareType();
+ }, $shares);
+ }, $children);
+
+ $keys = array_map(function (\OCP\Files\Node $node) {
+ return $node->getId();
+ }, $children);
+
+ return array_combine($keys, $values);
+ }
+
/**
* Adds shares to propfind response
*
@@ -156,15 +180,15 @@ class SharesPlugin extends \Sabre\DAV\ServerPlugin {
&& !is_null($propFind->getStatus(self::SHARETYPES_PROPERTYNAME))
) {
$folderNode = $this->userFolder->get($sabreNode->getPath());
- $children = $folderNode->getDirectoryListing();
+ $childShares = $this->getSharesTypesInFolder($folderNode);
$this->cachedShareTypes[$folderNode->getId()] = $this->getShareTypes($folderNode);
- foreach ($children as $childNode) {
- $this->cachedShareTypes[$childNode->getId()] = $this->getShareTypes($childNode);
+ foreach ($childShares as $id => $shares) {
+ $this->cachedShareTypes[$id] = $shares;
}
}
- $propFind->handle(self::SHARETYPES_PROPERTYNAME, function() use ($sabreNode) {
+ $propFind->handle(self::SHARETYPES_PROPERTYNAME, function () use ($sabreNode) {
if (isset($this->cachedShareTypes[$sabreNode->getId()])) {
$shareTypes = $this->cachedShareTypes[$sabreNode->getId()];
} else {
diff --git a/apps/dav/tests/unit/Connector/Sabre/SharesPluginTest.php b/apps/dav/tests/unit/Connector/Sabre/SharesPluginTest.php
index 433ef4ba63a..2e17c7d0b38 100644
--- a/apps/dav/tests/unit/Connector/Sabre/SharesPluginTest.php
+++ b/apps/dav/tests/unit/Connector/Sabre/SharesPluginTest.php
@@ -206,6 +206,14 @@ class SharesPluginTest extends \Test\TestCase {
->method('get')
->with('/subdir')
->will($this->returnValue($node));
+
+ $dummyShares = array_map(function($type) {
+ $share = $this->getMock('\OCP\Share\IShare');
+ $share->expects($this->any())
+ ->method('getShareType')
+ ->will($this->returnValue($type));
+ return $share;
+ }, $shareTypes);
$this->shareManager->expects($this->any())
->method('getSharesBy')
@@ -224,6 +232,17 @@ class SharesPluginTest extends \Test\TestCase {
return [];
}));
+ $this->shareManager->expects($this->any())
+ ->method('getSharesInFolder')
+ ->with(
+ $this->equalTo('user1'),
+ $this->anything(),
+ $this->equalTo(false)
+ )
+ ->will($this->returnCallback(function ($userId, $node, $flag) use ($shareTypes, $dummyShares) {
+ return [111 => $dummyShares];
+ }));
+
// simulate sabre recursive PROPFIND traversal
$propFindRoot = new \Sabre\DAV\PropFind(
'/subdir',