diff options
author | Carl Schwan <carl@carlschwan.eu> | 2022-04-22 10:01:35 +0200 |
---|---|---|
committer | Carl Schwan <carl@carlschwan.eu> | 2022-04-22 10:29:18 +0200 |
commit | ed4c1e584f685d18f77b5eca95e3a82826e8be5d (patch) | |
tree | a60e4324d2ac501dc4667a1dcadcbbca7e899442 /lib | |
parent | 4333c215cbc444f13fd07542a143e75f82609ac4 (diff) | |
download | nextcloud-server-ed4c1e584f685d18f77b5eca95e3a82826e8be5d.tar.gz nextcloud-server-ed4c1e584f685d18f77b5eca95e3a82826e8be5d.zip |
Update cache when display name change
This improve the correctness of the data
Signed-off-by: Carl Schwan <carl@carlschwan.eu>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/User/DisplayNameCache.php | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/lib/private/User/DisplayNameCache.php b/lib/private/User/DisplayNameCache.php index f44cdac6e85..ed0c723ef37 100644 --- a/lib/private/User/DisplayNameCache.php +++ b/lib/private/User/DisplayNameCache.php @@ -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 + } + } } |