summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorJoas Schilling <213943+nickvergessen@users.noreply.github.com>2022-08-22 19:17:47 +0200
committerGitHub <noreply@github.com>2022-08-22 19:17:47 +0200
commit8a22ebfdc9c8e9788afd77836e97a5b6f248c248 (patch)
tree8de7b875a40cbf39f0be4eed2225a5957d2644bd /lib
parentf5c87b49380ddb641f4ccd7da38f2d89d5aeed28 (diff)
parent62f47af2b6143d7c9ff1f24b1ffce2ff6951bc7f (diff)
Merge pull request #7770 from nextcloud/performance/7769/use-user-displayname-cache
Use user displayname cache
Diffstat (limited to 'lib')
-rw-r--r--lib/Activity/Provider/Base.php17
-rw-r--r--lib/Chat/AutoComplete/SearchPlugin.php20
-rw-r--r--lib/Chat/Notifier.php4
-rw-r--r--lib/Chat/Parser/UserMention.php5
-rw-r--r--lib/Controller/CallController.php7
-rw-r--r--lib/Controller/RoomController.php6
-rw-r--r--lib/Manager.php7
-rw-r--r--lib/Notification/Notifier.php26
-rw-r--r--lib/Service/ParticipantService.php8
9 files changed, 38 insertions, 62 deletions
diff --git a/lib/Activity/Provider/Base.php b/lib/Activity/Provider/Base.php
index f1cc6c499..0bb75b57c 100644
--- a/lib/Activity/Provider/Base.php
+++ b/lib/Activity/Provider/Base.php
@@ -43,9 +43,6 @@ abstract class Base implements IProvider {
protected IUserManager $userManager;
protected Manager $manager;
- /** @var string[] */
- protected array $displayNames = [];
-
public function __construct(IFactory $languageFactory,
IURLGenerator $url,
Config $config,
@@ -134,22 +131,10 @@ abstract class Base implements IProvider {
}
protected function getUser(string $uid): array {
- if (!isset($this->displayNames[$uid])) {
- $this->displayNames[$uid] = $this->getDisplayName($uid);
- }
-
return [
'type' => 'user',
'id' => $uid,
- 'name' => $this->displayNames[$uid],
+ 'name' => $this->userManager->getDisplayName($uid) ?? $uid,
];
}
-
- protected function getDisplayName(string $uid): string {
- $user = $this->userManager->get($uid);
- if ($user instanceof IUser) {
- return $user->getDisplayName();
- }
- return $uid;
- }
}
diff --git a/lib/Chat/AutoComplete/SearchPlugin.php b/lib/Chat/AutoComplete/SearchPlugin.php
index 9cabe3e85..1ca840db7 100644
--- a/lib/Chat/AutoComplete/SearchPlugin.php
+++ b/lib/Chat/AutoComplete/SearchPlugin.php
@@ -33,7 +33,6 @@ use OCP\Collaboration\Collaborators\ISearchPlugin;
use OCP\Collaboration\Collaborators\ISearchResult;
use OCP\Collaboration\Collaborators\SearchResultType;
use OCP\IL10N;
-use OCP\IUser;
use OCP\IUserManager;
class SearchPlugin implements ISearchPlugin {
@@ -139,18 +138,18 @@ class SearchPlugin implements ISearchPlugin {
continue;
}
- $user = $this->userManager->get($userId);
- if (!$user instanceof IUser) {
+ $userDisplayName = $this->userManager->getDisplayName($userId);
+ if ($userDisplayName === null) {
continue;
}
- if (strtolower($user->getDisplayName()) === $search) {
- $exactMatches[] = $this->createResult('user', $user->getUID(), $user->getDisplayName());
+ if (strtolower($userDisplayName) === $search) {
+ $exactMatches[] = $this->createResult('user', $userId, $userDisplayName);
continue;
}
- if (stripos($user->getDisplayName(), $search) !== false) {
- $matches[] = $this->createResult('user', $user->getUID(), $user->getDisplayName());
+ if (stripos($userDisplayName, $search) !== false) {
+ $matches[] = $this->createResult('user', $userId, $userDisplayName);
continue;
}
}
@@ -207,12 +206,7 @@ class SearchPlugin implements ISearchPlugin {
protected function createResult(string $type, string $uid, string $name): array {
if ($type === 'user' && $name === '') {
- $user = $this->userManager->get($uid);
- if ($user instanceof IUser) {
- $name = $user->getDisplayName();
- } else {
- $name = $uid;
- }
+ $name = $this->userManager->getDisplayName($uid) ?? $uid;
}
return [
diff --git a/lib/Chat/Notifier.php b/lib/Chat/Notifier.php
index 5874d05bf..3f048c056 100644
--- a/lib/Chat/Notifier.php
+++ b/lib/Chat/Notifier.php
@@ -467,11 +467,11 @@ class Notifier {
// so they can see the room in their room list and
// the notification can be parsed and links to an existing room,
// where they are a participant of.
- $user = $this->userManager->get($userId);
+ $userDisplayName = $this->userManager->getDisplayName($userId);
$this->participantService->addUsers($room, [[
'actorType' => Attendee::ACTOR_USERS,
'actorId' => $userId,
- 'displayName' => $user ? $user->getDisplayName() : $userId,
+ 'displayName' => $userDisplayName ?? $userId,
]]);
return true;
}
diff --git a/lib/Chat/Parser/UserMention.php b/lib/Chat/Parser/UserMention.php
index 531dbd037..4c4ba060e 100644
--- a/lib/Chat/Parser/UserMention.php
+++ b/lib/Chat/Parser/UserMention.php
@@ -31,7 +31,6 @@ use OCA\Talk\Model\Message;
use OCA\Talk\Room;
use OCP\Comments\ICommentsManager;
use OCP\IL10N;
-use OCP\IUser;
use OCP\IUserManager;
/**
@@ -91,8 +90,8 @@ class UserMention {
}
if ($mention['type'] === 'user') {
- $user = $this->userManager->get($mention['id']);
- if (!$user instanceof IUser) {
+ $userDisplayName = $this->userManager->getDisplayName($mention['id']);
+ if ($userDisplayName === null) {
continue;
}
}
diff --git a/lib/Controller/CallController.php b/lib/Controller/CallController.php
index f55b62bc7..5be4ae148 100644
--- a/lib/Controller/CallController.php
+++ b/lib/Controller/CallController.php
@@ -36,7 +36,6 @@ use OCP\AppFramework\Http;
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\IRequest;
-use OCP\IUser;
use OCP\IUserManager;
class CallController extends AEnvironmentAwareController {
@@ -78,9 +77,9 @@ class CallController extends AEnvironmentAwareController {
if ($participant->getAttendee()->getDisplayName()) {
$displayName = $participant->getAttendee()->getDisplayName();
} else {
- $user = $this->userManager->get($participant->getAttendee()->getActorId());
- if ($user instanceof IUser) {
- $displayName = $user->getDisplayName();
+ $userDisplayName = $this->userManager->getDisplayName($participant->getAttendee()->getActorId());
+ if ($userDisplayName !== null) {
+ $displayName = $userDisplayName;
}
}
} else {
diff --git a/lib/Controller/RoomController.php b/lib/Controller/RoomController.php
index 49e2e7a89..9f3e0fc85 100644
--- a/lib/Controller/RoomController.php
+++ b/lib/Controller/RoomController.php
@@ -1011,11 +1011,11 @@ class RoomController extends AEnvironmentAwareController {
$result['displayName'] = $participant->getAttendee()->getDisplayName();
if (!$result['displayName']) {
- $user = $this->userManager->get($userId);
- if (!$user instanceof IUser) {
+ $userDisplayName = $this->userManager->getDisplayName($userId);
+ if ($userDisplayName === null) {
continue;
}
- $result['displayName'] = $user->getDisplayName();
+ $result['displayName'] = $userDisplayName;
}
if (isset($statuses[$userId])) {
diff --git a/lib/Manager.php b/lib/Manager.php
index f72fc5c5b..1e2798ee0 100644
--- a/lib/Manager.php
+++ b/lib/Manager.php
@@ -1002,8 +1002,8 @@ class Manager {
}
if ($otherParticipant === '' && $room->getName() !== '') {
- $user = $this->userManager->get($room->getName());
- $otherParticipant = $user instanceof IUser ? $user->getDisplayName() : $this->l->t('Deleted user (%s)', $room->getName());
+ $userDisplayName = $this->userManager->getDisplayName($room->getName());
+ $otherParticipant = $userDisplayName ?? $this->l->t('Deleted user (%s)', $room->getName());
}
return $otherParticipant;
@@ -1054,8 +1054,7 @@ class Manager {
$displayNames = [];
foreach ($users as $participantId) {
- $user = $this->userManager->get($participantId);
- $displayNames[] = $user instanceof IUser ? $user->getDisplayName() : $participantId;
+ $displayNames[] = $this->userManager->getDisplayName($participantId) ?? $participantId;
}
$roomName = implode(', ', $displayNames);
diff --git a/lib/Notification/Notifier.php b/lib/Notification/Notifier.php
index 68af32113..77dbcfaf5 100644
--- a/lib/Notification/Notifier.php
+++ b/lib/Notification/Notifier.php
@@ -332,13 +332,13 @@ class Notifier implements INotifier {
$isGuest = false;
if ($subjectParameters['userType'] === 'users') {
$userId = $subjectParameters['userId'];
- $user = $this->userManager->get($userId);
+ $userDisplayName = $this->userManager->getDisplayName($userId);
- if ($user instanceof IUser) {
+ if ($userDisplayName !== null) {
$richSubjectUser = [
'type' => 'user',
'id' => $userId,
- 'name' => $user->getDisplayName(),
+ 'name' => $userDisplayName,
];
}
} else {
@@ -559,8 +559,8 @@ class Notifier implements INotifier {
$parameters = $notification->getSubjectParameters();
$uid = $parameters['actorId'] ?? $parameters[0];
- $user = $this->userManager->get($uid);
- if (!$user instanceof IUser) {
+ $userDisplayName = $this->userManager->getDisplayName($uid);
+ if ($userDisplayName === null) {
throw new AlreadyProcessedException();
}
@@ -574,13 +574,13 @@ class Notifier implements INotifier {
}
$notification
- ->setParsedSubject(str_replace('{user}', $user->getDisplayName(), $subject))
+ ->setParsedSubject(str_replace('{user}', $userDisplayName, $subject))
->setRichSubject(
$subject, [
'user' => [
'type' => 'user',
'id' => $uid,
- 'name' => $user->getDisplayName(),
+ 'name' => $userDisplayName,
],
'call' => [
'type' => 'call',
@@ -599,13 +599,13 @@ class Notifier implements INotifier {
}
$notification
- ->setParsedSubject(str_replace(['{user}', '{call}'], [$user->getDisplayName(), $roomName], $subject))
+ ->setParsedSubject(str_replace(['{user}', '{call}'], [$userDisplayName, $roomName], $subject))
->setRichSubject(
$subject, [
'user' => [
'type' => 'user',
'id' => $uid,
- 'name' => $user->getDisplayName(),
+ 'name' => $userDisplayName,
],
'call' => [
'type' => 'call',
@@ -639,8 +639,8 @@ class Notifier implements INotifier {
if ($room->getType() === Room::TYPE_ONE_TO_ONE) {
$parameters = $notification->getSubjectParameters();
$calleeId = $parameters['callee'];
- $user = $this->userManager->get($calleeId);
- if ($user instanceof IUser) {
+ $userDisplayName = $this->userManager->getDisplayName($calleeId);
+ if ($userDisplayName !== null) {
if ($this->notificationManager->isPreparingPushNotification() || $this->participantService->hasActiveSessionsInCall($room)) {
$notification = $this->addActionButton($notification, $l->t('Answer call'));
$subject = $l->t('{user} would like to talk with you');
@@ -650,13 +650,13 @@ class Notifier implements INotifier {
}
$notification
- ->setParsedSubject(str_replace('{user}', $user->getDisplayName(), $subject))
+ ->setParsedSubject(str_replace('{user}', $userDisplayName, $subject))
->setRichSubject(
$subject, [
'user' => [
'type' => 'user',
'id' => $calleeId,
- 'name' => $user->getDisplayName(),
+ 'name' => $userDisplayName,
],
'call' => [
'type' => 'call',
diff --git a/lib/Service/ParticipantService.php b/lib/Service/ParticipantService.php
index 852e33d7f..9742c2805 100644
--- a/lib/Service/ParticipantService.php
+++ b/lib/Service/ParticipantService.php
@@ -680,12 +680,12 @@ class ParticipantService {
$missingUsers = array_diff($users, $participants);
foreach ($missingUsers as $userId) {
- $user = $this->userManager->get($userId);
- if ($user instanceof IUser) {
+ $userDisplayName = $this->userManager->getDisplayName($userId);
+ if ($userDisplayName !== null) {
$this->addUsers($room, [[
'actorType' => Attendee::ACTOR_USERS,
- 'actorId' => $user->getUID(),
- 'displayName' => $user->getDisplayName(),
+ 'actorId' => $userId,
+ 'displayName' => $userDisplayName,
'participantType' => Participant::OWNER,
]]);
}