summaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorMorris Jobke <hey@morrisjobke.de>2018-09-27 17:20:13 +0200
committerGitHub <noreply@github.com>2018-09-27 17:20:13 +0200
commit065ec741734861923b5a8d5c61c10d3b6ecde378 (patch)
tree0db59a9635d909e9e1fbd69c8886191069bd4825 /apps
parent9c0a9a4d4692e42443aee2ae1b84e5559bb30da0 (diff)
parent6dae2b92508696c6b47216099abdd3f3fcd8497e (diff)
downloadnextcloud-server-065ec741734861923b5a8d5c61c10d3b6ecde378.tar.gz
nextcloud-server-065ec741734861923b5a8d5c61c10d3b6ecde378.zip
Merge pull request #10884 from nextcloud/large-share-count-performance-13
[13] Improve performance when dealing with large numbers of shares
Diffstat (limited to 'apps')
-rw-r--r--apps/files_sharing/lib/MountProvider.php25
-rw-r--r--apps/files_sharing/lib/SharedMount.php38
-rw-r--r--apps/files_sharing/lib/SharedStorage.php10
3 files changed, 49 insertions, 24 deletions
diff --git a/apps/files_sharing/lib/MountProvider.php b/apps/files_sharing/lib/MountProvider.php
index fd4c537210f..5623f18d662 100644
--- a/apps/files_sharing/lib/MountProvider.php
+++ b/apps/files_sharing/lib/MountProvider.php
@@ -27,6 +27,8 @@
namespace OCA\Files_Sharing;
+use OC\Cache\CappedMemoryCache;
+use OC\Files\View;
use OCP\Files\Config\IMountProvider;
use OCP\Files\Storage\IStorageFactory;
use OCP\IConfig;
@@ -83,20 +85,35 @@ class MountProvider implements IMountProvider {
$superShares = $this->buildSuperShares($shares, $user);
$mounts = [];
+ $view = new View('/' . $user->getUID() . '/files');
+ $ownerViews = [];
+ $sharingDisabledForUser = $this->shareManager->sharingDisabledForUser($user->getUID());
+ $foldersExistCache = new CappedMemoryCache();
foreach ($superShares as $share) {
try {
- $mounts[] = new SharedMount(
+ /** @var \OCP\Share\IShare $parentShare */
+ $parentShare = $share[0];
+ $owner = $parentShare->getShareOwner();
+ if (!isset($ownerViews[$owner])) {
+ $ownerViews[$owner] = new View('/' . $parentShare->getShareOwner() . '/files');
+ }
+ $mount = new SharedMount(
'\OCA\Files_Sharing\SharedStorage',
$mounts,
[
'user' => $user->getUID(),
// parent share
- 'superShare' => $share[0],
+ 'superShare' => $parentShare,
// children/component of the superShare
'groupedShares' => $share[1],
+ 'ownerView' => $ownerViews[$owner],
+ 'sharingDisabledForUser' => $sharingDisabledForUser
],
- $storageFactory
+ $storageFactory,
+ $view,
+ $foldersExistCache
);
+ $mounts[$mount->getMountPoint()] = $mount;
} catch (\Exception $e) {
$this->logger->logException($e);
$this->logger->error('Error while trying to create shared mount');
@@ -104,7 +121,7 @@ class MountProvider implements IMountProvider {
}
// array_filter removes the null values from the array
- return array_filter($mounts);
+ return array_values(array_filter($mounts));
}
/**
diff --git a/apps/files_sharing/lib/SharedMount.php b/apps/files_sharing/lib/SharedMount.php
index 4f0dc89e997..4b38698f81d 100644
--- a/apps/files_sharing/lib/SharedMount.php
+++ b/apps/files_sharing/lib/SharedMount.php
@@ -28,10 +28,12 @@
namespace OCA\Files_Sharing;
+use OC\Cache\CappedMemoryCache;
use OC\Files\Filesystem;
use OC\Files\Mount\MountPoint;
use OC\Files\Mount\MoveableMount;
use OC\Files\View;
+use OCP\Files\Storage\IStorageFactory;
/**
* Shared mount points can be moved by the user
@@ -61,19 +63,19 @@ class SharedMount extends MountPoint implements MoveableMount {
/**
* @param string $storage
* @param SharedMount[] $mountpoints
- * @param array|null $arguments
- * @param \OCP\Files\Storage\IStorageFactory $loader
+ * @param array $arguments
+ * @param IStorageFactory $loader
+ * @param View $recipientView
*/
- public function __construct($storage, array $mountpoints, $arguments = null, $loader = null) {
+ public function __construct($storage, array $mountpoints, $arguments, IStorageFactory $loader, View $recipientView, CappedMemoryCache $folderExistCache) {
$this->user = $arguments['user'];
- $this->recipientView = new View('/' . $this->user . '/files');
+ $this->recipientView = $recipientView;
$this->superShare = $arguments['superShare'];
$this->groupedShares = $arguments['groupedShares'];
- $newMountPoint = $this->verifyMountPoint($this->superShare, $mountpoints);
+ $newMountPoint = $this->verifyMountPoint($this->superShare, $mountpoints, $folderExistCache);
$absMountPoint = '/' . $this->user . '/files' . $newMountPoint;
- $arguments['ownerView'] = new View('/' . $this->superShare->getShareOwner() . '/files');
parent::__construct($storage, $absMountPoint, $arguments, $loader);
}
@@ -84,12 +86,18 @@ class SharedMount extends MountPoint implements MoveableMount {
* @param SharedMount[] $mountpoints
* @return string
*/
- private function verifyMountPoint(\OCP\Share\IShare $share, array $mountpoints) {
+ private function verifyMountPoint(\OCP\Share\IShare $share, array $mountpoints, CappedMemoryCache $folderExistCache) {
$mountPoint = basename($share->getTarget());
$parent = dirname($share->getTarget());
- if (!$this->recipientView->is_dir($parent)) {
+ if ($folderExistCache->hasKey($parent)) {
+ $parentExists = $folderExistCache->get($parent);
+ } else {
+ $parentExists = $this->recipientView->is_dir($parent);
+ $folderExistCache->set($parent, $parentExists);
+ }
+ if (!$parentExists) {
$parent = Helper::getShareFolder($this->recipientView);
}
@@ -135,19 +143,11 @@ class SharedMount extends MountPoint implements MoveableMount {
$name = $pathinfo['filename'];
$dir = $pathinfo['dirname'];
- // Helper function to find existing mount points
- $mountpointExists = function ($path) use ($mountpoints) {
- foreach ($mountpoints as $mountpoint) {
- if ($mountpoint->getShare()->getTarget() === $path) {
- return true;
- }
- }
- return false;
- };
-
$i = 2;
- while ($view->file_exists($path) || $mountpointExists($path)) {
+ $absolutePath = $this->recipientView->getAbsolutePath($path) . '/';
+ while ($view->file_exists($path) || isset($mountpoints[$absolutePath])) {
$path = Filesystem::normalizePath($dir . '/' . $name . ' (' . $i . ')' . $ext);
+ $absolutePath = $this->recipientView->getAbsolutePath($path) . '/';
$i++;
}
diff --git a/apps/files_sharing/lib/SharedStorage.php b/apps/files_sharing/lib/SharedStorage.php
index f681854cd2b..2d2f14fc554 100644
--- a/apps/files_sharing/lib/SharedStorage.php
+++ b/apps/files_sharing/lib/SharedStorage.php
@@ -79,6 +79,9 @@ class SharedStorage extends \OC\Files\Storage\Wrapper\Jail implements ISharedSto
private $options;
+ /** @var boolean */
+ private $sharingDisabledForUser;
+
public function __construct($arguments) {
$this->ownerView = $arguments['ownerView'];
$this->logger = \OC::$server->getLogger();
@@ -87,6 +90,11 @@ class SharedStorage extends \OC\Files\Storage\Wrapper\Jail implements ISharedSto
$this->groupedShares = $arguments['groupedShares'];
$this->user = $arguments['user'];
+ if (isset($arguments['sharingDisabledForUser'])) {
+ $this->sharingDisabledForUser = $arguments['sharingDisabledForUser'];
+ } else {
+ $this->sharingDisabledForUser = false;
+ }
parent::__construct([
'storage' => null,
@@ -193,7 +201,7 @@ class SharedStorage extends \OC\Files\Storage\Wrapper\Jail implements ISharedSto
$permissions |= \OCP\Constants::PERMISSION_DELETE;
}
- if (\OCP\Util::isSharingDisabledForUser()) {
+ if ($this->sharingDisabledForUser) {
$permissions &= ~\OCP\Constants::PERMISSION_SHARE;
}