]> source.dussan.org Git - nextcloud-server.git/commitdiff
Update cache when display name change 32047/head
authorCarl Schwan <carl@carlschwan.eu>
Fri, 22 Apr 2022 08:01:35 +0000 (10:01 +0200)
committerCarl Schwan <carl@carlschwan.eu>
Fri, 22 Apr 2022 08:29:18 +0000 (10:29 +0200)
This improve the correctness of the data

Signed-off-by: Carl Schwan <carl@carlschwan.eu>
apps/files_sharing/lib/AppInfo/Application.php
apps/files_sharing/lib/Cache.php
lib/private/User/DisplayNameCache.php

index befd1532d02605f3c07df4765a6db106489fcc0b..2539247b561bc070d4239a8babc1f80b6ea8a445 100644 (file)
@@ -30,6 +30,7 @@
 namespace OCA\Files_Sharing\AppInfo;
 
 use OC\Share\Share;
+use OC\User\DisplayNameCache;
 use OCA\Files_Sharing\Capabilities;
 use OCA\Files_Sharing\Event\BeforeTemplateRenderedEvent;
 use OCA\Files_Sharing\External\Manager;
@@ -65,6 +66,7 @@ use OCP\IUserSession;
 use OCP\L10N\IFactory;
 use OCP\Share\Events\ShareCreatedEvent;
 use OCP\Share\IManager;
+use OCP\User\Events\UserChangedEvent;
 use OCP\Util;
 use Psr\Container\ContainerInterface;
 use Symfony\Component\EventDispatcher\EventDispatcherInterface;
@@ -98,6 +100,7 @@ class Application extends App implements IBootstrap {
                $context->registerCapability(Capabilities::class);
 
                $context->registerNotifierService(Notifier::class);
+               $context->registerEventListener(UserChangedEvent::class, DisplayNameCache::class);
        }
 
        public function boot(IBootContext $context): void {
index 7290c33da948436047c8e65286cef4ccf6652b9a..9f11431008f3529ee54d6d0a3ee807af87c67b36 100644 (file)
@@ -53,7 +53,7 @@ class Cache extends CacheJail {
        private ICacheEntry $sourceRootInfo;
        private bool $rootUnchanged = true;
        private ?string $ownerDisplayName = null;
-       private int $numericId;
+       private $numericId;
        private DisplayNameCache $displayNameCache;
 
        /**
index f44cdac6e855636751afa5e72b53c8b675988ff2..ed0c723ef37d2aaf46dd85b2f7ced663a44f90f4 100644 (file)
@@ -23,9 +23,12 @@ declare(strict_types=1);
 
 namespace OC\User;
 
+use OCP\EventDispatcher\Event;
+use OCP\EventDispatcher\IEventListener;
 use OCP\ICache;
 use OCP\ICacheFactory;
 use OCP\IUserManager;
+use OCP\User\Events\UserChangedEvent;
 
 /**
  * Class that cache the relation UserId -> Display name
@@ -34,7 +37,7 @@ use OCP\IUserManager;
  * their preferences. It's generally not an issue if this data is slightly
  * outdated.
  */
-class DisplayNameCache {
+class DisplayNameCache implements IEventListener {
        private ICache $internalCache;
        private IUserManager $userManager;
 
@@ -63,4 +66,12 @@ class DisplayNameCache {
        public function clear(): void {
                $this->internalCache->clear();
        }
+
+       public function handle(Event $event): void {
+               if ($event instanceof UserChangedEvent && $event->getFeature() === 'displayName') {
+                       $userId = $event->getUser()->getUID();
+                       $newDisplayName = $event->getValue();
+                       $this->internalCache->set($userId, $newDisplayName, 60 * 10); // 10 minutes
+               }
+       }
 }