]> source.dussan.org Git - nextcloud-server.git/commitdiff
invalidate mount cache on circles change
authorRobin Appelman <robin@icewind.nl>
Thu, 17 Mar 2022 17:32:50 +0000 (18:32 +0100)
committerRobin Appelman <robin@icewind.nl>
Thu, 24 Mar 2022 16:03:52 +0000 (17:03 +0100)
Signed-off-by: Robin Appelman <robin@icewind.nl>
lib/private/Files/SetupManager.php

index 6da0bf21f8fe38d2c0963c4f4eab4a4f64c822ac..6746af1068e70014eea43199483851313987ce92 100644 (file)
@@ -103,22 +103,7 @@ class SetupManager {
                $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();
-                       }
-               });
+               $this->setupListeners();
        }
 
        private function isSetupStarted(IUser $user): bool {
@@ -213,7 +198,9 @@ class SetupManager {
                }
 
                $this->setupForUserWith($user, function () use ($user) {
-                       $this->mountProviderCollection->addMountForUser($user, $this->mountManager, function (IMountProvider $provider) use ($user) {
+                       $this->mountProviderCollection->addMountForUser($user, $this->mountManager, function (
+                               IMountProvider $provider
+                       ) use ($user) {
                                return !in_array(get_class($provider), $this->setupUserMountProviders[$user->getUID()]);
                        });
                });
@@ -433,7 +420,9 @@ class SetupManager {
        private function listenForNewMountProviders() {
                if (!$this->listeningForProviders) {
                        $this->listeningForProviders = true;
-                       $this->mountProviderCollection->listen('\OC\Files\Config', 'registerMountProvider', function (IMountProvider $provider) {
+                       $this->mountProviderCollection->listen('\OC\Files\Config', 'registerMountProvider', function (
+                               IMountProvider $provider
+                       ) {
                                foreach ($this->setupUsers as $userId) {
                                        $user = $this->userManager->get($userId);
                                        if ($user) {
@@ -444,4 +433,40 @@ class SetupManager {
                        });
                }
        }
+
+       private function setupListeners() {
+               // note that this event handling is intentionally pessimistic
+               // clearing the cache to often is better than not enough
+
+               $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());
+               });
+               $this->eventDispatcher->addListener(ShareCreatedEvent::class, function (ShareCreatedEvent $event) {
+                       $this->cache->remove($event->getShare()->getSharedWith());
+               });
+               $this->eventDispatcher->addListener(InvalidateMountCacheEvent::class, function (InvalidateMountCacheEvent $event
+               ) {
+                       if ($user = $event->getUser()) {
+                               $this->cache->remove($user->getUID());
+                       } else {
+                               $this->cache->clear();
+                       }
+               });
+
+               $genericEvents = [
+                       '\OCA\Circles::onCircleCreation',
+                       '\OCA\Circles::onCircleDestruction',
+                       '\OCA\Circles::onMemberNew',
+                       '\OCA\Circles::onMemberLeaving',
+               ];
+
+               foreach ($genericEvents as $genericEvent) {
+                       $this->eventDispatcher->addListener($genericEvent, function($event) {
+                               $this->cache->clear();
+                       });
+               }
+       }
 }