Skip to content

Commit

Permalink
Merge pull request #4903 from nextcloud/feat/display-name-cache
Browse files Browse the repository at this point in the history
feat: Use user display name cache
  • Loading branch information
blizzz authored Jul 20, 2023
2 parents 631b32d + 4a9e399 commit 554efab
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 11 deletions.
2 changes: 1 addition & 1 deletion lib/Db/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function __construct($uid, IUserManager $userManager) {
public function getObjectSerialization() {
return [
'uid' => $this->getObject()->getUID(),
'displayname' => $this->getObject()->getDisplayName(),
'displayname' => $this->getDisplayName(),
'type' => Acl::PERMISSION_TYPE_USER
];
}
Expand Down
3 changes: 1 addition & 2 deletions lib/Service/CommentService.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,7 @@ public function delete(string $cardId, string $commentId): DataResponse {
}

private function formatComment(IComment $comment, $addReplyTo = false): array {
$user = $this->userManager->get($comment->getActorId());
$actorDisplayName = $user !== null ? $user->getDisplayName() : $comment->getActorId();
$actorDisplayName = $this->userManager->getDisplayName($comment->getActorId()) ?? $comment->getActorId();

$formattedComment = [
'id' => (int)$comment->getId(),
Expand Down
3 changes: 1 addition & 2 deletions lib/Service/SearchService.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,7 @@ public function searchComments(string $term, ?int $limit = null, ?int $cursor =
$card = Card::fromRow($cardRow);
// TODO: Only perform one enrich call here
$self->cardService->enrichCards([$card]);
$user = $this->userManager->get($comment->getActorId());
$displayName = $user ? $user->getDisplayName() : '';
$displayName = $this->userManager->getDisplayName($comment->getActorId()) ?? '';
return new CommentSearchResultEntry($comment->getId(), $comment->getMessage(), $displayName, $card, $this->urlGenerator, $this->l10n);
}, $matchedComments);
}
Expand Down
12 changes: 6 additions & 6 deletions tests/unit/Db/UserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ public function testGroupObjectSerialize() {
$user->expects($this->any())
->method('getUID')
->willReturn('myuser');
$user->expects($this->any())
->method('getDisplayName')
->willReturn('myuser displayname');
$userManager = $this->createMock(IUserManager::class);
$userManager->expects($this->any())
->method('get')
->willReturn($user);
$userManager->expects($this->any())
->method('getDisplayName')
->willReturn('myuser displayname');
$userRelationalObject = new User('myuser', $userManager);
$expected = [
'uid' => 'myuser',
Expand All @@ -55,13 +55,13 @@ public function testGroupJSONSerialize() {
$user->expects($this->any())
->method('getUID')
->willReturn('myuser');
$user->expects($this->any())
->method('getDisplayName')
->willReturn('myuser displayname');
$userManager = $this->createMock(IUserManager::class);
$userManager->expects($this->any())
->method('get')
->willReturn($user);
$userManager->expects($this->any())
->method('getDisplayName')
->willReturn('myuser displayname');
$userRelationalObject = new User('myuser', $userManager);
$expected = [
'uid' => 'myuser',
Expand Down

0 comments on commit 554efab

Please sign in to comment.