*/
private $cachedShareTypes;
+ private $cachedFolders = [];
+
/**
* @param \Sabre\DAV\Tree $tree tree
* @param IUserSession $userSession user session
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;
}
/**
$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;
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);