]> source.dussan.org Git - nextcloud-server.git/commitdiff
make mount cache duration configurable
authorRobin Appelman <robin@icewind.nl>
Thu, 24 Mar 2022 14:47:50 +0000 (15:47 +0100)
committerRobin Appelman <robin@icewind.nl>
Thu, 24 Mar 2022 16:36:53 +0000 (17:36 +0100)
Signed-off-by: Robin Appelman <robin@icewind.nl>
lib/private/Files/SetupManager.php
lib/private/Files/SetupManagerFactory.php

index 4ef2506cf7be96f885c885472d55a913f6291b5c..cb39ec90245db4a58e5d8a7619020d5249614e11 100644 (file)
@@ -52,6 +52,7 @@ use OCP\Group\Events\UserAddedEvent;
 use OCP\Group\Events\UserRemovedEvent;
 use OCP\ICache;
 use OCP\ICacheFactory;
+use OCP\IConfig;
 use OCP\IUser;
 use OCP\IUserManager;
 use OCP\IUserSession;
@@ -77,6 +78,7 @@ class SetupManager {
        private IUserSession $userSession;
        private ICache $cache;
        private LoggerInterface $logger;
+       private IConfig $config;
        private bool $listeningForProviders;
 
        public function __construct(
@@ -89,7 +91,8 @@ class SetupManager {
                ILockdownManager $lockdownManager,
                IUserSession $userSession,
                ICacheFactory $cacheFactory,
-               LoggerInterface $logger
+               LoggerInterface $logger,
+               IConfig $config
        ) {
                $this->eventLogger = $eventLogger;
                $this->mountProviderCollection = $mountProviderCollection;
@@ -102,6 +105,7 @@ class SetupManager {
                $this->userSession = $userSession;
                $this->cache = $cacheFactory->createDistributed('setupmanager::');
                $this->listeningForProviders = false;
+               $this->config = $config;
 
                $this->setupListeners();
        }
@@ -204,7 +208,7 @@ class SetupManager {
                                return !in_array(get_class($provider), $this->setupUserMountProviders[$user->getUID()]);
                        });
                });
-               $this->userFullySetup($user);
+               $this->afterUserFullySetup($user);
        }
 
        /**
@@ -249,7 +253,10 @@ class SetupManager {
                $this->listenForNewMountProviders();
        }
 
-       private function userFullySetup(IUser $user) {
+       /**
+        * Final housekeeping after a user has been fully setup
+        */
+       private function afterUserFullySetup(IUser $user): void {
                $userRoot = '/' . $user->getUID() . '/';
                $mounts = $this->mountManager->getAll();
                $mounts = array_filter($mounts, function (IMountPoint $mount) use ($userRoot) {
@@ -348,7 +355,11 @@ class SetupManager {
                $cachedSetup = $this->cache->get($user->getUID());
                if (!$cachedSetup) {
                        $this->setupForUser($user);
-                       $this->cache->set($user->getUID(), true, 5 * 60);
+
+                       $cacheDuration = $this->config->getSystemValueInt('fs_mount_cache_duration', 5 * 60);
+                       if ($cacheDuration > 0) {
+                               $this->cache->set($user->getUID(), true, $cacheDuration);
+                       }
                        return;
                }
 
@@ -379,7 +390,7 @@ class SetupManager {
                }
 
                if ($includeChildren) {
-                       $subCachedMounts = $this->userMountCache->getMountsInForPath($user, $path);
+                       $subCachedMounts = $this->userMountCache->getMountsInPath($user, $path);
                        foreach ($subCachedMounts as $cachedMount) {
                                if (!in_array($cachedMount->getMountProvider(), $setupProviders)) {
                                        $setupProviders[] = $cachedMount->getMountProvider();
index d361d42aad9369faf52241f31117d69fcac6f98e..1d9efbd411fbeff836480d249dc84ebccb00dbb6 100644 (file)
@@ -29,6 +29,7 @@ use OCP\Files\Config\IMountProviderCollection;
 use OCP\Files\Config\IUserMountCache;
 use OCP\Files\Mount\IMountManager;
 use OCP\ICacheFactory;
+use OCP\IConfig;
 use OCP\IUserManager;
 use OCP\IUserSession;
 use OCP\Lockdown\ILockdownManager;
@@ -45,6 +46,7 @@ class SetupManagerFactory {
        private ?SetupManager $setupManager;
        private ICacheFactory $cacheFactory;
        private LoggerInterface $logger;
+       private IConfig $config;
 
        public function __construct(
                IEventLogger $eventLogger,
@@ -55,7 +57,8 @@ class SetupManagerFactory {
                ILockdownManager $lockdownManager,
                IUserSession $userSession,
                ICacheFactory $cacheFactory,
-               LoggerInterface $logger
+               LoggerInterface $logger,
+               IConfig $config
        ) {
                $this->eventLogger = $eventLogger;
                $this->mountProviderCollection = $mountProviderCollection;
@@ -66,6 +69,7 @@ class SetupManagerFactory {
                $this->userSession = $userSession;
                $this->cacheFactory = $cacheFactory;
                $this->logger = $logger;
+               $this->config = $config;
                $this->setupManager = null;
        }
 
@@ -81,7 +85,8 @@ class SetupManagerFactory {
                                $this->lockdownManager,
                                $this->userSession,
                                $this->cacheFactory,
-                               $this->logger
+                               $this->logger,
+                               $this->config
                        );
                }
                return $this->setupManager;