diff options
author | Robin Appelman <robin@icewind.nl> | 2022-04-21 17:43:51 +0200 |
---|---|---|
committer | Robin Appelman <robin@icewind.nl> | 2022-04-21 18:08:35 +0200 |
commit | bda86016480ade925125977fbe20a7c2b05389d0 (patch) | |
tree | db34101ee5638d35f8d635fdbfa5e6f5fa2dd108 /apps | |
parent | caebdc2a559f995ff5672cdea7c46a5febaa1ea5 (diff) | |
download | nextcloud-server-bda86016480ade925125977fbe20a7c2b05389d0.tar.gz nextcloud-server-bda86016480ade925125977fbe20a7c2b05389d0.zip |
cache the verification of the share mountpoint
after the initial verification this can only really be invalidated by a system mount (external/group/etc) being created at the share target since any normal file/folder creation will already conflict with the share
Signed-off-by: Robin Appelman <robin@icewind.nl>
Diffstat (limited to 'apps')
-rw-r--r-- | apps/files_sharing/lib/MountProvider.php | 11 | ||||
-rw-r--r-- | apps/files_sharing/lib/SharedMount.php | 22 | ||||
-rw-r--r-- | apps/files_sharing/tests/MountProviderTest.php | 7 |
3 files changed, 35 insertions, 5 deletions
diff --git a/apps/files_sharing/lib/MountProvider.php b/apps/files_sharing/lib/MountProvider.php index 27edf5074e1..bfb40387622 100644 --- a/apps/files_sharing/lib/MountProvider.php +++ b/apps/files_sharing/lib/MountProvider.php @@ -34,6 +34,7 @@ use OCA\Files_Sharing\Event\ShareMountedEvent; use OCP\EventDispatcher\IEventDispatcher; use OCP\Files\Config\IMountProvider; use OCP\Files\Storage\IStorageFactory; +use OCP\ICacheFactory; use OCP\IConfig; use OCP\ILogger; use OCP\IUser; @@ -59,6 +60,9 @@ class MountProvider implements IMountProvider { /** @var IEventDispatcher */ protected $eventDispatcher; + /** @var ICacheFactory */ + protected $cacheFactory; + /** * @param \OCP\IConfig $config * @param IManager $shareManager @@ -68,12 +72,14 @@ class MountProvider implements IMountProvider { IConfig $config, IManager $shareManager, ILogger $logger, - IEventDispatcher $eventDispatcher + IEventDispatcher $eventDispatcher, + ICacheFactory $cacheFactory ) { $this->config = $config; $this->shareManager = $shareManager; $this->logger = $logger; $this->eventDispatcher = $eventDispatcher; + $this->cacheFactory = $cacheFactory; } @@ -136,7 +142,8 @@ class MountProvider implements IMountProvider { $view, $foldersExistCache, $this->eventDispatcher, - $user + $user, + $this->cacheFactory->createLocal('share-valid-mountpoint') ); $event = new ShareMountedEvent($mount); diff --git a/apps/files_sharing/lib/SharedMount.php b/apps/files_sharing/lib/SharedMount.php index 60361e25fd0..398da5eaf23 100644 --- a/apps/files_sharing/lib/SharedMount.php +++ b/apps/files_sharing/lib/SharedMount.php @@ -26,6 +26,7 @@ * along with this program. If not, see <http://www.gnu.org/licenses/> * */ + namespace OCA\Files_Sharing; use OC\Cache\CappedMemoryCache; @@ -36,6 +37,7 @@ use OC\Files\View; use OCP\EventDispatcher\IEventDispatcher; use OCP\Files\Events\InvalidateMountCacheEvent; use OCP\Files\Storage\IStorageFactory; +use OCP\ICache; use OCP\IUser; use OCP\Share\Events\VerifyMountPointEvent; @@ -63,6 +65,8 @@ class SharedMount extends MountPoint implements MoveableMount { private IEventDispatcher $eventDispatcher; + private ICache $cache; + public function __construct( $storage, array $mountpoints, @@ -71,11 +75,13 @@ class SharedMount extends MountPoint implements MoveableMount { View $recipientView, CappedMemoryCache $folderExistCache, IEventDispatcher $eventDispatcher, - IUser $user + IUser $user, + ICache $cache ) { $this->user = $user; $this->recipientView = $recipientView; $this->eventDispatcher = $eventDispatcher; + $this->cache = $cache; $this->superShare = $arguments['superShare']; $this->groupedShares = $arguments['groupedShares']; @@ -92,7 +98,17 @@ class SharedMount extends MountPoint implements MoveableMount { * @param SharedMount[] $mountpoints * @return string */ - private function verifyMountPoint(\OCP\Share\IShare $share, array $mountpoints, CappedMemoryCache $folderExistCache) { + private function verifyMountPoint( + \OCP\Share\IShare $share, + array $mountpoints, + CappedMemoryCache $folderExistCache + ) { + $cacheKey = $this->user->getUID() . '/' . $share->getTarget(); + $cached = $this->cache->get($cacheKey); + if ($cached !== null) { + return $cached; + } + $mountPoint = basename($share->getTarget()); $parent = dirname($share->getTarget()); @@ -120,6 +136,8 @@ class SharedMount extends MountPoint implements MoveableMount { $this->updateFileTarget($newMountPoint, $share); } + $this->cache->set($cacheKey, $newMountPoint, 60 * 60); + return $newMountPoint; } diff --git a/apps/files_sharing/tests/MountProviderTest.php b/apps/files_sharing/tests/MountProviderTest.php index 756c6f95d42..00ae847eaac 100644 --- a/apps/files_sharing/tests/MountProviderTest.php +++ b/apps/files_sharing/tests/MountProviderTest.php @@ -29,10 +29,12 @@ */ namespace OCA\Files_Sharing\Tests; +use OC\Memcache\NullCache; use OCA\Files_Sharing\MountProvider; use OCP\EventDispatcher\IEventDispatcher; use OCP\Files\IRootFolder; use OCP\Files\Storage\IStorageFactory; +use OCP\ICacheFactory; use OCP\IConfig; use OCP\ILogger; use OCP\IUser; @@ -72,8 +74,11 @@ class MountProviderTest extends \Test\TestCase { $this->shareManager = $this->getMockBuilder(IManager::class)->getMock(); $this->logger = $this->getMockBuilder(ILogger::class)->getMock(); $eventDispatcher = $this->createMock(IEventDispatcher::class); + $cacheFactory = $this->createMock(ICacheFactory::class); + $cacheFactory->method('createLocal') + ->willReturn(new NullCache()); - $this->provider = new MountProvider($this->config, $this->shareManager, $this->logger, $eventDispatcher); + $this->provider = new MountProvider($this->config, $this->shareManager, $this->logger, $eventDispatcher, $cacheFactory); } private function makeMockShare($id, $nodeId, $owner = 'user2', $target = null, $permissions = 31) { |