summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoas Schilling <213943+nickvergessen@users.noreply.github.com>2022-08-17 11:59:36 +0200
committerGitHub <noreply@github.com>2022-08-17 11:59:36 +0200
commit5871010f430c9775b1a20ad0feb249f3f2675301 (patch)
tree43103e0ea13903a31377639a8ed834d2733fff18
parenta819743148d195de1d680bf291898a7e7185acfa (diff)
parent724db041e1ea4986ebb0dc4fb07b25363b5c96ab (diff)
Merge pull request #7750 from nextcloud/performance/optimize-retrival-of-rooms
Use DisplayNameCache
-rw-r--r--composer.lock8
-rw-r--r--lib/Chat/MessageParser.php4
-rw-r--r--lib/Chat/Parser/SystemMessage.php7
-rw-r--r--lib/Manager.php3
-rw-r--r--tests/php/Chat/Parser/SystemMessageTest.php11
5 files changed, 12 insertions, 21 deletions
diff --git a/composer.lock b/composer.lock
index 524f88e16..11614843a 100644
--- a/composer.lock
+++ b/composer.lock
@@ -242,12 +242,12 @@
"source": {
"type": "git",
"url": "https://github.com/ChristophWurst/nextcloud_composer.git",
- "reference": "577103cb24552d134a6338014fe665cabfd9c2c8"
+ "reference": "433f70a9ddfece0233927997ae5ff38070fc1fcc"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/ChristophWurst/nextcloud_composer/zipball/577103cb24552d134a6338014fe665cabfd9c2c8",
- "reference": "577103cb24552d134a6338014fe665cabfd9c2c8",
+ "url": "https://api.github.com/repos/ChristophWurst/nextcloud_composer/zipball/433f70a9ddfece0233927997ae5ff38070fc1fcc",
+ "reference": "433f70a9ddfece0233927997ae5ff38070fc1fcc",
"shasum": ""
},
"require": {
@@ -278,7 +278,7 @@
"issues": "https://github.com/ChristophWurst/nextcloud_composer/issues",
"source": "https://github.com/ChristophWurst/nextcloud_composer/tree/master"
},
- "time": "2022-08-09T02:21:50+00:00"
+ "time": "2022-08-17T02:31:52+00:00"
},
{
"name": "composer/package-versions-deprecated",
diff --git a/lib/Chat/MessageParser.php b/lib/Chat/MessageParser.php
index 5428b9f7c..e64287c48 100644
--- a/lib/Chat/MessageParser.php
+++ b/lib/Chat/MessageParser.php
@@ -34,7 +34,6 @@ use OCA\Talk\Room;
use OCP\Comments\IComment;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\IL10N;
-use OCP\IUser;
use OCP\IUserManager;
/**
@@ -79,8 +78,7 @@ class MessageParser {
$actorId = $comment->getActorId();
$displayName = '';
if ($comment->getActorType() === Attendee::ACTOR_USERS) {
- $user = $this->userManager->get($comment->getActorId());
- $displayName = $user instanceof IUser ? $user->getDisplayName() : $comment->getActorId();
+ $displayName = $this->userManager->getDisplayName($comment->getActorId()) ?? $comment->getActorId();
} elseif ($comment->getActorType() === Attendee::ACTOR_BRIDGED) {
$displayName = $comment->getActorId();
$actorId = MatterbridgeManager::BRIDGE_BOT_USERID;
diff --git a/lib/Chat/Parser/SystemMessage.php b/lib/Chat/Parser/SystemMessage.php
index 4c1230f0c..51666142d 100644
--- a/lib/Chat/Parser/SystemMessage.php
+++ b/lib/Chat/Parser/SystemMessage.php
@@ -44,7 +44,6 @@ use OCP\IGroupManager;
use OCP\IL10N;
use OCP\IPreview as IPreviewManager;
use OCP\IURLGenerator;
-use OCP\IUser;
use OCP\IUserManager;
use OCP\Server;
use OCP\Share\Exceptions\ShareNotFound;
@@ -698,9 +697,9 @@ class SystemMessage {
}
protected function getDisplayName(string $uid): string {
- $user = $this->userManager->get($uid);
- if ($user instanceof IUser) {
- return $user->getDisplayName();
+ $userName = $this->userManager->getDisplayName($uid);
+ if ($userName !== null) {
+ return $userName;
}
throw new ParticipantNotFoundException();
diff --git a/lib/Manager.php b/lib/Manager.php
index 5acf16c2c..f72fc5c5b 100644
--- a/lib/Manager.php
+++ b/lib/Manager.php
@@ -990,8 +990,7 @@ class Manager {
foreach ($users as $participantId) {
if ($participantId !== $userId) {
- $user = $this->userManager->get($participantId);
- $otherParticipant = $user instanceof IUser ? $user->getDisplayName() : $participantId;
+ $otherParticipant = $this->userManager->getDisplayName($participantId) ?? $participantId;
} else {
$userIsParticipant = true;
}
diff --git a/tests/php/Chat/Parser/SystemMessageTest.php b/tests/php/Chat/Parser/SystemMessageTest.php
index ad9daae63..1ffa7d5d1 100644
--- a/tests/php/Chat/Parser/SystemMessageTest.php
+++ b/tests/php/Chat/Parser/SystemMessageTest.php
@@ -44,7 +44,6 @@ use OCP\IGroupManager;
use OCP\IL10N;
use OCP\IPreview as IPreviewManager;
use OCP\IURLGenerator;
-use OCP\IUser;
use OCP\IUserManager;
use OCP\Share\Exceptions\ShareNotFound;
use OCP\Share\IShare;
@@ -948,17 +947,13 @@ class SystemMessageTest extends TestCase {
$parser = $this->getParser();
if ($validUser) {
- $user = $this->createMock(IUser::class);
- $user->expects($this->once())
- ->method('getDisplayName')
- ->willReturn($name);
$this->userManager->expects($this->once())
- ->method('get')
+ ->method('getDisplayName')
->with($uid)
- ->willReturn($user);
+ ->willReturn($name);
} else {
$this->userManager->expects($this->once())
- ->method('get')
+ ->method('getDisplayName')
->with($uid)
->willReturn(null);
$this->expectException(ParticipantNotFoundException::class);