]> source.dussan.org Git - nextcloud-server.git/commitdiff
fix(cache): Remove displayname cache entry on delete 40080/head
authorJoas Schilling <coding@schilljs.com>
Mon, 28 Aug 2023 12:59:54 +0000 (14:59 +0200)
committerbackportbot-nextcloud[bot] <backportbot-nextcloud[bot]@users.noreply.github.com>
Mon, 28 Aug 2023 16:18:59 +0000 (16:18 +0000)
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 eff4a3ac5b749b2dbc028ab5dc1e904b98b42454..483a54d168d473026f66ab7407707f20f968f980 100644 (file)
@@ -68,6 +68,7 @@ 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;
@@ -76,6 +77,7 @@ use OCP\L10N\IFactory;
 use OCP\Share\Events\ShareCreatedEvent;
 use OCP\Share\IManager;
 use OCP\User\Events\UserChangedEvent;
+use OCP\User\Events\UserDeletedEvent;
 use OCP\Util;
 use Psr\Container\ContainerInterface;
 use Symfony\Component\EventDispatcher\EventDispatcherInterface;
@@ -110,7 +112,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);
+               }
        }
 }