diff options
author | Morris Jobke <hey@morrisjobke.de> | 2018-09-27 17:09:36 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-09-27 17:09:36 +0200 |
commit | ca2f2c227d7ea45ff63d32638a648212d3b30723 (patch) | |
tree | 16e7abb3c17320dd5d572afd6b9381041be093e4 /apps | |
parent | a6304378b0b6cb6fa32721bc3d61678716b651a4 (diff) | |
parent | a6e78a4db6a44c6376e6e27b0c4461cd4a97a5dc (diff) | |
download | nextcloud-server-ca2f2c227d7ea45ff63d32638a648212d3b30723.tar.gz nextcloud-server-ca2f2c227d7ea45ff63d32638a648212d3b30723.zip |
Merge pull request #10882 from nextcloud/large-share-count-performance-12
[12] Improve performance when dealing with large numbers of shares
Diffstat (limited to 'apps')
-rw-r--r-- | apps/files_sharing/lib/MountProvider.php | 25 | ||||
-rw-r--r-- | apps/files_sharing/lib/SharedMount.php | 38 | ||||
-rw-r--r-- | apps/files_sharing/lib/SharedStorage.php | 10 |
3 files changed, 49 insertions, 24 deletions
diff --git a/apps/files_sharing/lib/MountProvider.php b/apps/files_sharing/lib/MountProvider.php index a02d6350499..8208e5fc755 100644 --- a/apps/files_sharing/lib/MountProvider.php +++ b/apps/files_sharing/lib/MountProvider.php @@ -25,6 +25,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; @@ -81,20 +83,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'); @@ -102,7 +119,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 b42682ab2a8..96e9bc000ab 100644 --- a/apps/files_sharing/lib/SharedMount.php +++ b/apps/files_sharing/lib/SharedMount.php @@ -27,10 +27,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 @@ -60,19 +62,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); } @@ -83,12 +85,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); } @@ -134,19 +142,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 32304afea01..4855b8cc61c 100644 --- a/apps/files_sharing/lib/SharedStorage.php +++ b/apps/files_sharing/lib/SharedStorage.php @@ -78,6 +78,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(); @@ -86,6 +89,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, @@ -192,7 +200,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; } |