diff options
author | Robin Appelman <robin@icewind.nl> | 2022-03-10 20:27:54 +0300 |
---|---|---|
committer | Robin Appelman <robin@icewind.nl> | 2022-03-24 19:03:10 +0300 |
commit | 6b085b6fd162aa288da17a27a553da34e1391412 (patch) | |
tree | cc10dc0c4f42c8368e6b8b466b99cdc267f6e441 /lib | |
parent | 506d29c095e0ff880605bd8e521572ed60c98438 (diff) |
add logic to perform a full filesystem setup when needed
Signed-off-by: Robin Appelman <robin@icewind.nl>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/composer/composer/autoload_classmap.php | 2 | ||||
-rw-r--r-- | lib/composer/composer/autoload_static.php | 2 | ||||
-rw-r--r-- | lib/private/Files/SetupManager.php | 38 | ||||
-rw-r--r-- | lib/private/Files/SetupManagerFactory.php | 7 | ||||
-rw-r--r-- | lib/public/Files/Events/InvalidateMountCacheEvent.php | 45 |
5 files changed, 92 insertions, 2 deletions
diff --git a/lib/composer/composer/autoload_classmap.php b/lib/composer/composer/autoload_classmap.php index 2ce5d448518..ad5e8047f6b 100644 --- a/lib/composer/composer/autoload_classmap.php +++ b/lib/composer/composer/autoload_classmap.php @@ -260,6 +260,7 @@ return array( 'OCP\\Files\\Events\\FileCacheUpdated' => $baseDir . '/lib/public/Files/Events/FileCacheUpdated.php', 'OCP\\Files\\Events\\FileScannedEvent' => $baseDir . '/lib/public/Files/Events/FileScannedEvent.php', 'OCP\\Files\\Events\\FolderScannedEvent' => $baseDir . '/lib/public/Files/Events/FolderScannedEvent.php', + 'OCP\\Files\\Events\\InvalidateMountCacheEvent' => $baseDir . '/lib/public/Files/Events/InvalidateMountCacheEvent.php', 'OCP\\Files\\Events\\NodeAddedToCache' => $baseDir . '/lib/public/Files/Events/NodeAddedToCache.php', 'OCP\\Files\\Events\\NodeRemovedFromCache' => $baseDir . '/lib/public/Files/Events/NodeRemovedFromCache.php', 'OCP\\Files\\Events\\Node\\AbstractNodeEvent' => $baseDir . '/lib/public/Files/Events/Node/AbstractNodeEvent.php', @@ -1140,6 +1141,7 @@ return array( 'OC\\Files\\Node\\HookConnector' => $baseDir . '/lib/private/Files/Node/HookConnector.php', 'OC\\Files\\Node\\LazyFolder' => $baseDir . '/lib/private/Files/Node/LazyFolder.php', 'OC\\Files\\Node\\LazyRoot' => $baseDir . '/lib/private/Files/Node/LazyRoot.php', + 'OC\\Files\\Node\\LazyUserFolder' => $baseDir . '/lib/private/Files/Node/LazyUserFolder.php', 'OC\\Files\\Node\\Node' => $baseDir . '/lib/private/Files/Node/Node.php', 'OC\\Files\\Node\\NonExistingFile' => $baseDir . '/lib/private/Files/Node/NonExistingFile.php', 'OC\\Files\\Node\\NonExistingFolder' => $baseDir . '/lib/private/Files/Node/NonExistingFolder.php', diff --git a/lib/composer/composer/autoload_static.php b/lib/composer/composer/autoload_static.php index 4c35c1d1f85..e7288503f63 100644 --- a/lib/composer/composer/autoload_static.php +++ b/lib/composer/composer/autoload_static.php @@ -289,6 +289,7 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c 'OCP\\Files\\Events\\FileCacheUpdated' => __DIR__ . '/../../..' . '/lib/public/Files/Events/FileCacheUpdated.php', 'OCP\\Files\\Events\\FileScannedEvent' => __DIR__ . '/../../..' . '/lib/public/Files/Events/FileScannedEvent.php', 'OCP\\Files\\Events\\FolderScannedEvent' => __DIR__ . '/../../..' . '/lib/public/Files/Events/FolderScannedEvent.php', + 'OCP\\Files\\Events\\InvalidateMountCacheEvent' => __DIR__ . '/../../..' . '/lib/public/Files/Events/InvalidateMountCacheEvent.php', 'OCP\\Files\\Events\\NodeAddedToCache' => __DIR__ . '/../../..' . '/lib/public/Files/Events/NodeAddedToCache.php', 'OCP\\Files\\Events\\NodeRemovedFromCache' => __DIR__ . '/../../..' . '/lib/public/Files/Events/NodeRemovedFromCache.php', 'OCP\\Files\\Events\\Node\\AbstractNodeEvent' => __DIR__ . '/../../..' . '/lib/public/Files/Events/Node/AbstractNodeEvent.php', @@ -1169,6 +1170,7 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c 'OC\\Files\\Node\\HookConnector' => __DIR__ . '/../../..' . '/lib/private/Files/Node/HookConnector.php', 'OC\\Files\\Node\\LazyFolder' => __DIR__ . '/../../..' . '/lib/private/Files/Node/LazyFolder.php', 'OC\\Files\\Node\\LazyRoot' => __DIR__ . '/../../..' . '/lib/private/Files/Node/LazyRoot.php', + 'OC\\Files\\Node\\LazyUserFolder' => __DIR__ . '/../../..' . '/lib/private/Files/Node/LazyUserFolder.php', 'OC\\Files\\Node\\Node' => __DIR__ . '/../../..' . '/lib/private/Files/Node/Node.php', 'OC\\Files\\Node\\NonExistingFile' => __DIR__ . '/../../..' . '/lib/private/Files/Node/NonExistingFile.php', 'OC\\Files\\Node\\NonExistingFolder' => __DIR__ . '/../../..' . '/lib/private/Files/Node/NonExistingFolder.php', 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; diff --git a/lib/public/Files/Events/InvalidateMountCacheEvent.php b/lib/public/Files/Events/InvalidateMountCacheEvent.php new file mode 100644 index 00000000000..ea8a9ea2788 --- /dev/null +++ b/lib/public/Files/Events/InvalidateMountCacheEvent.php @@ -0,0 +1,45 @@ +<?php + +declare(strict_types=1); +/** + * @copyright Copyright (c) 2022 Robin Appelman <robin@icewind.nl> + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ + +namespace OCP\Files\Events; + +use OCP\EventDispatcher\Event; +use OCP\IUser; + +/** + * Used to notify the filesystem setup manager that the available mounts for a user have changed + * + * @since 24.0.0 + */ +class InvalidateMountCacheEvent extends Event { + private ?IUser $user; + + public function __construct(?IUser $user) { + parent::__construct(); + $this->user = $user; + } + + public function getUser(): ?IUser { + return $this->user; + } +} |