diff options
author | Robin Appelman <robin@icewind.nl> | 2025-04-08 15:36:29 +0200 |
---|---|---|
committer | Robin Appelman <robin@icewind.nl> | 2025-04-08 16:42:01 +0200 |
commit | bcbf0e76a73a2ca17d483b03c4222b072bf3db9c (patch) | |
tree | a252076c9ecf0790b987924447bb99f921b23bc6 /apps/files_sharing/lib/MountProvider.php | |
parent | 403c33a640a5ffe57ce68d4c097fe74d94431145 (diff) | |
download | nextcloud-server-shared-target-verify-cache.tar.gz nextcloud-server-shared-target-verify-cache.zip |
fix: more optimized caching for share target verificationshared-target-verify-cache
Signed-off-by: Robin Appelman <robin@icewind.nl>
Diffstat (limited to 'apps/files_sharing/lib/MountProvider.php')
-rw-r--r-- | apps/files_sharing/lib/MountProvider.php | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/apps/files_sharing/lib/MountProvider.php b/apps/files_sharing/lib/MountProvider.php index ad9498371d3..ea99023676b 100644 --- a/apps/files_sharing/lib/MountProvider.php +++ b/apps/files_sharing/lib/MountProvider.php @@ -11,6 +11,7 @@ use OCA\Files_Sharing\Event\ShareMountedEvent; use OCP\Cache\CappedMemoryCache; use OCP\EventDispatcher\IEventDispatcher; use OCP\Files\Config\IMountProvider; +use OCP\Files\Mount\IMountManager; use OCP\Files\Mount\IMountPoint; use OCP\Files\Storage\IStorageFactory; use OCP\ICacheFactory; @@ -32,6 +33,7 @@ class MountProvider implements IMountProvider { protected LoggerInterface $logger, protected IEventDispatcher $eventDispatcher, protected ICacheFactory $cacheFactory, + protected IMountManager $mountManager, ) { } @@ -58,12 +60,17 @@ class MountProvider implements IMountProvider { $superShares = $this->buildSuperShares($shares, $user); - $mounts = []; + $mounts = $this->mountManager->getAll(); $view = new View('/' . $user->getUID() . '/files'); $ownerViews = []; $sharingDisabledForUser = $this->shareManager->sharingDisabledForUser($user->getUID()); /** @var CappedMemoryCache<bool> $folderExistCache */ $foldersExistCache = new CappedMemoryCache(); + + $validShareCache = $this->cacheFactory->createLocal('share-valid-mountpoint-max'); + $maxValidatedShare = $validShareCache->get($user->getUID()) ?? 0; + $newMaxValidatedShare = $maxValidatedShare; + foreach ($superShares as $share) { try { /** @var IShare $parentShare */ @@ -80,6 +87,7 @@ class MountProvider implements IMountProvider { if (!isset($ownerViews[$owner])) { $ownerViews[$owner] = new View('/' . $parentShare->getShareOwner() . '/files'); } + $shareId = (int)$parentShare->getId(); $mount = new SharedMount( '\OCA\Files_Sharing\SharedStorage', $mounts, @@ -97,9 +105,11 @@ class MountProvider implements IMountProvider { $foldersExistCache, $this->eventDispatcher, $user, - $this->cacheFactory->createLocal('share-valid-mountpoint') + ($shareId <= $maxValidatedShare) ); + $newMaxValidatedShare = max($shareId, $newMaxValidatedShare); + $event = new ShareMountedEvent($mount); $this->eventDispatcher->dispatchTyped($event); @@ -118,6 +128,8 @@ class MountProvider implements IMountProvider { } } + $validShareCache->set($user->getUID(), $newMaxValidatedShare, 24 * 60 * 60); + // array_filter removes the null values from the array return array_values(array_filter($mounts)); } |