cache parent exists status during share setup

Signed-off-by: Robin Appelman <robin@icewind.nl>
This commit is contained in:
Robin Appelman 2018-08-16 21:05:01 +02:00
parent b3c714db75
commit a6e78a4db6
No known key found for this signature in database
GPG Key ID: 42B69D8A64526EFB
3 changed files with 17 additions and 10 deletions

View File

@ -237,10 +237,6 @@ class Helper {
return $path; return $path;
} }
public static function isUsingShareFolder() {
return \OC::$server->getConfig()->getSystemValue('share_folder', '/') !== '/';
}
/** /**
* get default share folder * get default share folder
* *

View File

@ -25,6 +25,7 @@
namespace OCA\Files_Sharing; namespace OCA\Files_Sharing;
use OC\Cache\CappedMemoryCache;
use OC\Files\View; use OC\Files\View;
use OCP\Files\Config\IMountProvider; use OCP\Files\Config\IMountProvider;
use OCP\Files\Storage\IStorageFactory; use OCP\Files\Storage\IStorageFactory;
@ -85,6 +86,7 @@ class MountProvider implements IMountProvider {
$view = new View('/' . $user->getUID() . '/files'); $view = new View('/' . $user->getUID() . '/files');
$ownerViews = []; $ownerViews = [];
$sharingDisabledForUser = $this->shareManager->sharingDisabledForUser($user->getUID()); $sharingDisabledForUser = $this->shareManager->sharingDisabledForUser($user->getUID());
$foldersExistCache = new CappedMemoryCache();
foreach ($superShares as $share) { foreach ($superShares as $share) {
try { try {
/** @var \OCP\Share\IShare $parentShare */ /** @var \OCP\Share\IShare $parentShare */
@ -106,7 +108,8 @@ class MountProvider implements IMountProvider {
'sharingDisabledForUser' => $sharingDisabledForUser 'sharingDisabledForUser' => $sharingDisabledForUser
], ],
$storageFactory, $storageFactory,
$view $view,
$foldersExistCache
); );
$mounts[$mount->getMountPoint()] = $mount; $mounts[$mount->getMountPoint()] = $mount;
} catch (\Exception $e) { } catch (\Exception $e) {

View File

@ -27,10 +27,12 @@
namespace OCA\Files_Sharing; namespace OCA\Files_Sharing;
use OC\Cache\CappedMemoryCache;
use OC\Files\Filesystem; use OC\Files\Filesystem;
use OC\Files\Mount\MountPoint; use OC\Files\Mount\MountPoint;
use OC\Files\Mount\MoveableMount; use OC\Files\Mount\MoveableMount;
use OC\Files\View; use OC\Files\View;
use OCP\Files\Storage\IStorageFactory;
/** /**
* Shared mount points can be moved by the user * Shared mount points can be moved by the user
@ -61,17 +63,17 @@ class SharedMount extends MountPoint implements MoveableMount {
* @param string $storage * @param string $storage
* @param SharedMount[] $mountpoints * @param SharedMount[] $mountpoints
* @param array $arguments * @param array $arguments
* @param \OCP\Files\Storage\IStorageFactory $loader * @param IStorageFactory $loader
* @param View $recipientView * @param View $recipientView
*/ */
public function __construct($storage, array $mountpoints, $arguments, $loader, $recipientView) { public function __construct($storage, array $mountpoints, $arguments, IStorageFactory $loader, View $recipientView, CappedMemoryCache $folderExistCache) {
$this->user = $arguments['user']; $this->user = $arguments['user'];
$this->recipientView = $recipientView; $this->recipientView = $recipientView;
$this->superShare = $arguments['superShare']; $this->superShare = $arguments['superShare'];
$this->groupedShares = $arguments['groupedShares']; $this->groupedShares = $arguments['groupedShares'];
$newMountPoint = $this->verifyMountPoint($this->superShare, $mountpoints); $newMountPoint = $this->verifyMountPoint($this->superShare, $mountpoints, $folderExistCache);
$absMountPoint = '/' . $this->user . '/files' . $newMountPoint; $absMountPoint = '/' . $this->user . '/files' . $newMountPoint;
parent::__construct($storage, $absMountPoint, $arguments, $loader); parent::__construct($storage, $absMountPoint, $arguments, $loader);
} }
@ -83,12 +85,18 @@ class SharedMount extends MountPoint implements MoveableMount {
* @param SharedMount[] $mountpoints * @param SharedMount[] $mountpoints
* @return string * @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()); $mountPoint = basename($share->getTarget());
$parent = dirname($share->getTarget()); $parent = dirname($share->getTarget());
if (Helper::isUsingShareFolder() && !$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); $parent = Helper::getShareFolder($this->recipientView);
} }