]> source.dussan.org Git - nextcloud-server.git/commitdiff
fix(cache): Remove displayname cache entry on delete 40077/head
authorJoas Schilling <coding@schilljs.com>
Mon, 28 Aug 2023 12:59:54 +0000 (14:59 +0200)
committerJoas Schilling <coding@schilljs.com>
Mon, 28 Aug 2023 12:59:54 +0000 (14:59 +0200)
Signed-off-by: Joas Schilling <coding@schilljs.com>
apps/files_sharing/lib/AppInfo/Application.php
lib/private/Group/DisplayNameCache.php
lib/private/User/DisplayNameCache.php

index b76239dc00d19c2f7994b2a73b403f9cf14917b6..603527310aee12735558d9d9667726393aeb041f 100644 (file)
@@ -65,12 +65,14 @@ use OCP\Files\Events\BeforeDirectFileDownloadEvent;
 use OCP\Files\Events\BeforeZipCreatedEvent;
 use OCP\Files\IRootFolder;
 use OCP\Group\Events\GroupChangedEvent;
+use OCP\Group\Events\GroupDeletedEvent;
 use OCP\Group\Events\UserAddedEvent;
 use OCP\IDBConnection;
 use OCP\IGroup;
 use OCP\IUserSession;
 use OCP\Share\Events\ShareCreatedEvent;
 use OCP\User\Events\UserChangedEvent;
+use OCP\User\Events\UserDeletedEvent;
 use OCP\Util;
 use Psr\Container\ContainerInterface;
 use Symfony\Component\EventDispatcher\GenericEvent as OldGenericEvent;
@@ -104,7 +106,9 @@ class Application extends App implements IBootstrap {
 
                $context->registerNotifierService(Notifier::class);
                $context->registerEventListener(UserChangedEvent::class, DisplayNameCache::class);
+               $context->registerEventListener(UserDeletedEvent::class, DisplayNameCache::class);
                $context->registerEventListener(GroupChangedEvent::class, GroupDisplayNameCache::class);
+               $context->registerEventListener(GroupDeletedEvent::class, GroupDisplayNameCache::class);
        }
 
        public function boot(IBootContext $context): void {
index d724b6caf0e151c2d3c835062606fbd2a5980e61..4eb8211be6eb124e600d81db65bf351a33ad8acf 100644 (file)
@@ -29,6 +29,7 @@ use OCP\Cache\CappedMemoryCache;
 use OCP\EventDispatcher\Event;
 use OCP\EventDispatcher\IEventListener;
 use OCP\Group\Events\GroupChangedEvent;
+use OCP\Group\Events\GroupDeletedEvent;
 use OCP\ICache;
 use OCP\ICacheFactory;
 use OCP\IGroupManager;
@@ -83,5 +84,10 @@ class DisplayNameCache implements IEventListener {
                        $this->cache[$groupId] = $newDisplayName;
                        $this->memCache->set($groupId, $newDisplayName, 60 * 10); // 10 minutes
                }
+               if ($event instanceof GroupDeletedEvent) {
+                       $groupId = $event->getGroup()->getGID();
+                       unset($this->cache[$groupId]);
+                       $this->memCache->remove($groupId);
+               }
        }
 }
index 5d1cc8940d760acbd0d31033d3ddc934e67b5361..6ee74cc9f6ce837dc26a0813ce9f3aaf2f8d0fd5 100644 (file)
@@ -29,6 +29,7 @@ use OCP\ICache;
 use OCP\ICacheFactory;
 use OCP\IUserManager;
 use OCP\User\Events\UserChangedEvent;
+use OCP\User\Events\UserDeletedEvent;
 
 /**
  * Class that cache the relation UserId -> Display name
@@ -81,5 +82,10 @@ class DisplayNameCache implements IEventListener {
                        $this->cache[$userId] = $newDisplayName;
                        $this->memCache->set($userId, $newDisplayName, 60 * 10); // 10 minutes
                }
+               if ($event instanceof UserDeletedEvent) {
+                       $userId = $event->getUser()->getUID();
+                       unset($this->cache[$userId]);
+                       $this->memCache->remove($userId);
+               }
        }
 }