Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarl Schwan <carl@carlschwan.eu>2022-04-22 11:01:35 +0300
committerArthur Schiwon <blizzz@arthur-schiwon.de>2022-04-22 16:22:16 +0300
commit40ac4e81976f2acceafce2d8c5b7e4aec2dba044 (patch)
tree63c32d70c68a84b0ac299dceb0442561999681b1
parent3d49fe473a934c3fc9e17afadba3cbddd423603d (diff)
Update cache when display name change
This improve the correctness of the data Signed-off-by: Carl Schwan <carl@carlschwan.eu>
-rw-r--r--apps/files_sharing/lib/AppInfo/Application.php3
-rw-r--r--apps/files_sharing/lib/Cache.php2
-rw-r--r--lib/private/User/DisplayNameCache.php13
3 files changed, 16 insertions, 2 deletions
diff --git a/apps/files_sharing/lib/AppInfo/Application.php b/apps/files_sharing/lib/AppInfo/Application.php
index befd1532d02..2539247b561 100644
--- a/apps/files_sharing/lib/AppInfo/Application.php
+++ b/apps/files_sharing/lib/AppInfo/Application.php
@@ -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 {
diff --git a/apps/files_sharing/lib/Cache.php b/apps/files_sharing/lib/Cache.php
index 3482a9fc71a..d245727b138 100644
--- a/apps/files_sharing/lib/Cache.php
+++ b/apps/files_sharing/lib/Cache.php
@@ -52,7 +52,7 @@ class Cache extends CacheJail {
private ICacheEntry $sourceRootInfo;
private bool $rootUnchanged = true;
private ?string $ownerDisplayName = null;
- private int $numericId;
+ private $numericId;
private DisplayNameCache $displayNameCache;
/**
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
+ }
+ }
}