aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnna <anna@nextcloud.com>2022-11-03 13:58:58 +0100
committerGitHub <noreply@github.com>2022-11-03 13:58:58 +0100
commitd648518136b86d73eeaf5664c6b7d8d6de009e2a (patch)
treee9fe995675fb548473258851914e69c214537d5f
parentc00e590a4f0bd1d7308c5f7b24ca55e3e9c4df78 (diff)
parent9dd51601c666a55317a98204c47968fa30baf15f (diff)
downloadnextcloud-server-d648518136b86d73eeaf5664c6b7d8d6de009e2a.tar.gz
nextcloud-server-d648518136b86d73eeaf5664c6b7d8d6de009e2a.zip
Merge pull request #33605 from nextcloud/perf/user-getdisplayname-cache
Use cached getDisplayName method
-rw-r--r--apps/dav/lib/CalDAV/Activity/Provider/Base.php3
-rw-r--r--apps/dav/lib/CalDAV/CalDavBackend.php21
-rw-r--r--apps/dav/lib/CalDAV/Schedule/IMipPlugin.php9
-rw-r--r--apps/dav/lib/CardDAV/CardDavBackend.php16
-rw-r--r--apps/dav/tests/unit/CalDAV/Schedule/IMipPluginTest.php7
5 files changed, 6 insertions, 50 deletions
diff --git a/apps/dav/lib/CalDAV/Activity/Provider/Base.php b/apps/dav/lib/CalDAV/Activity/Provider/Base.php
index 48ed7b8b107..672129a8311 100644
--- a/apps/dav/lib/CalDAV/Activity/Provider/Base.php
+++ b/apps/dav/lib/CalDAV/Activity/Provider/Base.php
@@ -38,9 +38,6 @@ abstract class Base implements IProvider {
/** @var IUserManager */
protected $userManager;
- /** @var string[] */
- protected $userDisplayNames = [];
-
/** @var IGroupManager */
protected $groupManager;
diff --git a/apps/dav/lib/CalDAV/CalDavBackend.php b/apps/dav/lib/CalDAV/CalDavBackend.php
index b00a4f9d6ed..a894b65d756 100644
--- a/apps/dav/lib/CalDAV/CalDavBackend.php
+++ b/apps/dav/lib/CalDAV/CalDavBackend.php
@@ -417,7 +417,7 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
[, $name] = Uri\split($row['principaluri']);
$uri = $row['uri'] . '_shared_by_' . $name;
- $row['displayname'] = $row['displayname'] . ' (' . $this->getUserDisplayName($name) . ')';
+ $row['displayname'] = $row['displayname'] . ' (' . ($this->userManager->getDisplayName($name) ?? ($name ?? '')) . ')';
$components = [];
if ($row['components']) {
$components = explode(',',$row['components']);
@@ -493,25 +493,6 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
return array_values($calendars);
}
-
- /**
- * @param $uid
- * @return string
- */
- private function getUserDisplayName($uid) {
- if (!isset($this->userDisplayNames[$uid])) {
- $user = $this->userManager->get($uid);
-
- if ($user instanceof IUser) {
- $this->userDisplayNames[$uid] = $user->getDisplayName();
- } else {
- $this->userDisplayNames[$uid] = $uid;
- }
- }
-
- return $this->userDisplayNames[$uid];
- }
-
/**
* @return array
*/
diff --git a/apps/dav/lib/CalDAV/Schedule/IMipPlugin.php b/apps/dav/lib/CalDAV/Schedule/IMipPlugin.php
index 2c7b06a4396..515072fd227 100644
--- a/apps/dav/lib/CalDAV/Schedule/IMipPlugin.php
+++ b/apps/dav/lib/CalDAV/Schedule/IMipPlugin.php
@@ -178,12 +178,7 @@ class IMipPlugin extends SabreIMipPlugin {
$recipientName = $iTipMessage->recipientName ?: null;
if ($senderName === null || empty(trim($senderName))) {
- $user = $this->userManager->get($this->userId);
- if ($user) {
- // getDisplayName automatically uses the uid
- // if no display-name is set
- $senderName = $user->getDisplayName();
- }
+ $senderName = $this->userManager->getDisplayName($this->userId);
}
/** @var VEvent $vevent */
@@ -225,7 +220,7 @@ class IMipPlugin extends SabreIMipPlugin {
];
$fromEMail = Util::getDefaultEmailAddress('invitations-noreply');
- $fromName = $l10n->t('%1$s via %2$s', [$senderName, $this->defaults->getName()]);
+ $fromName = $l10n->t('%1$s via %2$s', [$senderName ?? $this->userId, $this->defaults->getName()]);
$message = $this->mailer->createMessage()
->setFrom([$fromEMail => $fromName])
diff --git a/apps/dav/lib/CardDAV/CardDavBackend.php b/apps/dav/lib/CardDAV/CardDavBackend.php
index 72499ad3037..03ddb93c084 100644
--- a/apps/dav/lib/CardDAV/CardDavBackend.php
+++ b/apps/dav/lib/CardDAV/CardDavBackend.php
@@ -207,7 +207,7 @@ class CardDavBackend implements BackendInterface, SyncSupport {
[, $name] = \Sabre\Uri\split($row['principaluri']);
$uri = $row['uri'] . '_shared_by_' . $name;
- $displayName = $row['displayname'] . ' (' . $this->getUserDisplayName($name) . ')';
+ $displayName = $row['displayname'] . ' (' . ($this->userManager->getDisplayName($name) ?? $name ?? '') . ')';
$addressBooks[$row['id']] = [
'id' => $row['id'],
@@ -256,20 +256,6 @@ class CardDavBackend implements BackendInterface, SyncSupport {
return array_values($addressBooks);
}
- private function getUserDisplayName($uid) {
- if (!isset($this->userDisplayNames[$uid])) {
- $user = $this->userManager->get($uid);
-
- if ($user instanceof IUser) {
- $this->userDisplayNames[$uid] = $user->getDisplayName();
- } else {
- $this->userDisplayNames[$uid] = $uid;
- }
- }
-
- return $this->userDisplayNames[$uid];
- }
-
/**
* @param int $addressBookId
*/
diff --git a/apps/dav/tests/unit/CalDAV/Schedule/IMipPluginTest.php b/apps/dav/tests/unit/CalDAV/Schedule/IMipPluginTest.php
index 0d8076f7aa4..0b64704a87e 100644
--- a/apps/dav/tests/unit/CalDAV/Schedule/IMipPluginTest.php
+++ b/apps/dav/tests/unit/CalDAV/Schedule/IMipPluginTest.php
@@ -183,13 +183,10 @@ class IMipPluginTest extends TestCase {
$message = $this->_testMessage();
$message->senderName = null;
- $user = $this->createMock(IUser::class);
- $user->method('getDisplayName')->willReturn('Mr. Wizard');
-
$this->userManager->expects($this->once())
- ->method('get')
+ ->method('getDisplayName')
->with('user123')
- ->willReturn($user);
+ ->willReturn('Mr. Wizard');
$this->_expectSend();
$this->plugin->schedule($message);