diff options
author | Robin Appelman <robin@icewind.nl> | 2022-03-10 18:27:54 +0100 |
---|---|---|
committer | Robin Appelman <robin@icewind.nl> | 2022-03-24 17:03:10 +0100 |
commit | 6b085b6fd162aa288da17a27a553da34e1391412 (patch) | |
tree | cc10dc0c4f42c8368e6b8b466b99cdc267f6e441 /lib/private/Files | |
parent | 506d29c095e0ff880605bd8e521572ed60c98438 (diff) | |
download | nextcloud-server-6b085b6fd162aa288da17a27a553da34e1391412.tar.gz nextcloud-server-6b085b6fd162aa288da17a27a553da34e1391412.zip |
add logic to perform a full filesystem setup when needed
Signed-off-by: Robin Appelman <robin@icewind.nl>
Diffstat (limited to 'lib/private/Files')
-rw-r--r-- | lib/private/Files/SetupManager.php | 38 | ||||
-rw-r--r-- | lib/private/Files/SetupManagerFactory.php | 7 |
2 files changed, 43 insertions, 2 deletions
diff --git a/lib/private/Files/SetupManager.php b/lib/private/Files/SetupManager.php index ace408ecb49..7e091da0e01 100644 --- a/lib/private/Files/SetupManager.php +++ b/lib/private/Files/SetupManager.php @@ -42,15 +42,21 @@ use OCP\Diagnostics\IEventLogger; use OCP\EventDispatcher\IEventDispatcher; use OCP\Files\Config\IMountProvider; use OCP\Files\Config\IUserMountCache; +use OCP\Files\Events\InvalidateMountCacheEvent; use OCP\Files\Events\Node\FilesystemTornDownEvent; use OCP\Files\Mount\IMountManager; use OCP\Files\Mount\IMountPoint; use OCP\Files\NotFoundException; use OCP\Files\Storage\IStorage; +use OCP\Group\Events\UserAddedEvent; +use OCP\Group\Events\UserRemovedEvent; +use OCP\ICache; +use OCP\ICacheFactory; use OCP\IUser; use OCP\IUserManager; use OCP\IUserSession; use OCP\Lockdown\ILockdownManager; +use OCP\Share\Events\ShareCreatedEvent; class SetupManager { private bool $rootSetup = false; @@ -68,6 +74,7 @@ class SetupManager { private IUserMountCache $userMountCache; private ILockdownManager $lockdownManager; private IUserSession $userSession; + private ICache $cache; private bool $listeningForProviders; public function __construct( @@ -78,7 +85,8 @@ class SetupManager { IEventDispatcher $eventDispatcher, IUserMountCache $userMountCache, ILockdownManager $lockdownManager, - IUserSession $userSession + IUserSession $userSession, + ICacheFactory $cacheFactory ) { $this->eventLogger = $eventLogger; $this->mountProviderCollection = $mountProviderCollection; @@ -88,7 +96,25 @@ class SetupManager { $this->userMountCache = $userMountCache; $this->lockdownManager = $lockdownManager; $this->userSession = $userSession; + $this->cache = $cacheFactory->createDistributed('setupmanager::'); $this->listeningForProviders = false; + + $this->eventDispatcher->addListener(UserAddedEvent::class, function(UserAddedEvent $event) { + $this->cache->remove($event->getUser()->getUID()); + }); + $this->eventDispatcher->addListener(UserRemovedEvent::class, function(UserRemovedEvent $event) { + $this->cache->remove($event->getUser()->getUID()); + }); + $eventDispatcher->addListener(ShareCreatedEvent::class, function(ShareCreatedEvent $event) { + $this->cache->remove($event->getShare()->getSharedWith()); + }); + $eventDispatcher->addListener(InvalidateMountCacheEvent::class, function(InvalidateMountCacheEvent $event) { + if ($user = $event->getUser()) { + $this->cache->remove($user->getUID()); + } else { + $this->cache->clear(); + } + }); } private function isSetupStarted(IUser $user): bool { @@ -319,6 +345,16 @@ class SetupManager { return; } + // we perform a "cached" setup only after having done the full setup recently + // this is also used to trigger a full setup after handling events that are likely + // to change the available mounts + $cachedSetup = $this->cache->get($user->getUID()); + if (!$cachedSetup) { + $this->setupForUser($user); + $this->cache->set($user->getUID(), true, 5 * 60); + return; + } + if (!isset($this->setupUserMountProviders[$user->getUID()])) { $this->setupUserMountProviders[$user->getUID()] = []; } diff --git a/lib/private/Files/SetupManagerFactory.php b/lib/private/Files/SetupManagerFactory.php index 56e70d09961..122f82c02e9 100644 --- a/lib/private/Files/SetupManagerFactory.php +++ b/lib/private/Files/SetupManagerFactory.php @@ -28,6 +28,7 @@ use OCP\EventDispatcher\IEventDispatcher; use OCP\Files\Config\IMountProviderCollection; use OCP\Files\Config\IUserMountCache; use OCP\Files\Mount\IMountManager; +use OCP\ICacheFactory; use OCP\IUserManager; use OCP\IUserSession; use OCP\Lockdown\ILockdownManager; @@ -41,6 +42,7 @@ class SetupManagerFactory { private ILockdownManager $lockdownManager; private IUserSession $userSession; private ?SetupManager $setupManager; + private ICacheFactory $cacheFactory; public function __construct( IEventLogger $eventLogger, @@ -49,7 +51,8 @@ class SetupManagerFactory { IEventDispatcher $eventDispatcher, IUserMountCache $userMountCache, ILockdownManager $lockdownManager, - IUserSession $userSession + IUserSession $userSession, + ICacheFactory $cacheFactory ) { $this->eventLogger = $eventLogger; $this->mountProviderCollection = $mountProviderCollection; @@ -58,6 +61,7 @@ class SetupManagerFactory { $this->userMountCache = $userMountCache; $this->lockdownManager = $lockdownManager; $this->userSession = $userSession; + $this->cacheFactory = $cacheFactory; $this->setupManager = null; } @@ -72,6 +76,7 @@ class SetupManagerFactory { $this->userMountCache, $this->lockdownManager, $this->userSession, + $this->cacheFactory ); } return $this->setupManager; |