@@ -38,48 +38,48 @@ |
||
| 38 | 38 | * outdated. |
| 39 | 39 | */ |
| 40 | 40 | class DisplayNameCache implements IEventListener { |
| 41 | - private array $cache = []; |
|
| 42 | - private ICache $memCache; |
|
| 43 | - private IUserManager $userManager; |
|
| 41 | + private array $cache = []; |
|
| 42 | + private ICache $memCache; |
|
| 43 | + private IUserManager $userManager; |
|
| 44 | 44 | |
| 45 | - public function __construct(ICacheFactory $cacheFactory, IUserManager $userManager) { |
|
| 46 | - $this->memCache = $cacheFactory->createDistributed('displayNameMappingCache'); |
|
| 47 | - $this->userManager = $userManager; |
|
| 48 | - } |
|
| 45 | + public function __construct(ICacheFactory $cacheFactory, IUserManager $userManager) { |
|
| 46 | + $this->memCache = $cacheFactory->createDistributed('displayNameMappingCache'); |
|
| 47 | + $this->userManager = $userManager; |
|
| 48 | + } |
|
| 49 | 49 | |
| 50 | - public function getDisplayName(string $userId) { |
|
| 51 | - if (isset($this->cache[$userId])) { |
|
| 52 | - return $this->cache[$userId]; |
|
| 53 | - } |
|
| 54 | - $displayName = $this->memCache->get($userId); |
|
| 55 | - if ($displayName) { |
|
| 56 | - $this->cache[$userId] = $displayName; |
|
| 57 | - return $displayName; |
|
| 58 | - } |
|
| 50 | + public function getDisplayName(string $userId) { |
|
| 51 | + if (isset($this->cache[$userId])) { |
|
| 52 | + return $this->cache[$userId]; |
|
| 53 | + } |
|
| 54 | + $displayName = $this->memCache->get($userId); |
|
| 55 | + if ($displayName) { |
|
| 56 | + $this->cache[$userId] = $displayName; |
|
| 57 | + return $displayName; |
|
| 58 | + } |
|
| 59 | 59 | |
| 60 | - $user = $this->userManager->get($userId); |
|
| 61 | - if ($user) { |
|
| 62 | - $displayName = $user->getDisplayName(); |
|
| 63 | - } else { |
|
| 64 | - $displayName = $userId; |
|
| 65 | - } |
|
| 66 | - $this->cache[$userId] = $displayName; |
|
| 67 | - $this->memCache->set($userId, $displayName, 60 * 10); // 10 minutes |
|
| 60 | + $user = $this->userManager->get($userId); |
|
| 61 | + if ($user) { |
|
| 62 | + $displayName = $user->getDisplayName(); |
|
| 63 | + } else { |
|
| 64 | + $displayName = $userId; |
|
| 65 | + } |
|
| 66 | + $this->cache[$userId] = $displayName; |
|
| 67 | + $this->memCache->set($userId, $displayName, 60 * 10); // 10 minutes |
|
| 68 | 68 | |
| 69 | - return $displayName; |
|
| 70 | - } |
|
| 69 | + return $displayName; |
|
| 70 | + } |
|
| 71 | 71 | |
| 72 | - public function clear(): void { |
|
| 73 | - $this->cache = []; |
|
| 74 | - $this->memCache->clear(); |
|
| 75 | - } |
|
| 72 | + public function clear(): void { |
|
| 73 | + $this->cache = []; |
|
| 74 | + $this->memCache->clear(); |
|
| 75 | + } |
|
| 76 | 76 | |
| 77 | - public function handle(Event $event): void { |
|
| 78 | - if ($event instanceof UserChangedEvent && $event->getFeature() === 'displayName') { |
|
| 79 | - $userId = $event->getUser()->getUID(); |
|
| 80 | - $newDisplayName = $event->getValue(); |
|
| 81 | - $this->cache[$userId] = $newDisplayName; |
|
| 82 | - $this->memCache->set($userId, $newDisplayName, 60 * 10); // 10 minutes |
|
| 83 | - } |
|
| 84 | - } |
|
| 77 | + public function handle(Event $event): void { |
|
| 78 | + if ($event instanceof UserChangedEvent && $event->getFeature() === 'displayName') { |
|
| 79 | + $userId = $event->getUser()->getUID(); |
|
| 80 | + $newDisplayName = $event->getValue(); |
|
| 81 | + $this->cache[$userId] = $newDisplayName; |
|
| 82 | + $this->memCache->set($userId, $newDisplayName, 60 * 10); // 10 minutes |
|
| 83 | + } |
|
| 84 | + } |
|
| 85 | 85 | } |