aboutsummaryrefslogtreecommitdiffstats
path: root/apps/dav
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2022-08-18 23:52:34 +0200
committerJoas Schilling <coding@schilljs.com>2022-08-19 10:48:32 +0200
commit7e1177819023a185480b5251e3a22dc429948518 (patch)
tree66288b17692cfcdde3e3273051e00224b4167b1f /apps/dav
parentcab0f1327e28104ef61e8767f963d20cf38544af (diff)
downloadnextcloud-server-7e1177819023a185480b5251e3a22dc429948518.tar.gz
nextcloud-server-7e1177819023a185480b5251e3a22dc429948518.zip
Use user name cache in activity providers
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'apps/dav')
-rw-r--r--apps/dav/lib/CalDAV/Activity/Provider/Base.php24
-rw-r--r--apps/dav/lib/CardDAV/Activity/Provider/Base.php22
-rw-r--r--apps/dav/tests/unit/CalDAV/Activity/Provider/BaseTest.php37
3 files changed, 3 insertions, 80 deletions
diff --git a/apps/dav/lib/CalDAV/Activity/Provider/Base.php b/apps/dav/lib/CalDAV/Activity/Provider/Base.php
index 7f70980a72b..48ed7b8b107 100644
--- a/apps/dav/lib/CalDAV/Activity/Provider/Base.php
+++ b/apps/dav/lib/CalDAV/Activity/Provider/Base.php
@@ -112,35 +112,15 @@ abstract class Base implements IProvider {
];
}
- /**
- * @param string $uid
- * @return array
- */
- protected function generateUserParameter($uid) {
- if (!isset($this->userDisplayNames[$uid])) {
- $this->userDisplayNames[$uid] = $this->getUserDisplayName($uid);
- }
-
+ protected function generateUserParameter(string $uid): array {
return [
'type' => 'user',
'id' => $uid,
- 'name' => $this->userDisplayNames[$uid],
+ 'name' => $this->userManager->getDisplayName($uid) ?? $uid,
];
}
/**
- * @param string $uid
- * @return string
- */
- protected function getUserDisplayName($uid) {
- $user = $this->userManager->get($uid);
- if ($user instanceof IUser) {
- return $user->getDisplayName();
- }
- return $uid;
- }
-
- /**
* @param string $gid
* @return array
*/
diff --git a/apps/dav/lib/CardDAV/Activity/Provider/Base.php b/apps/dav/lib/CardDAV/Activity/Provider/Base.php
index 2f6de31de15..3e7a966c08a 100644
--- a/apps/dav/lib/CardDAV/Activity/Provider/Base.php
+++ b/apps/dav/lib/CardDAV/Activity/Provider/Base.php
@@ -98,35 +98,15 @@ abstract class Base implements IProvider {
];
}
- /**
- * @param string $uid
- * @return array
- */
protected function generateUserParameter(string $uid): array {
- if (!isset($this->userDisplayNames[$uid])) {
- $this->userDisplayNames[$uid] = $this->getUserDisplayName($uid);
- }
-
return [
'type' => 'user',
'id' => $uid,
- 'name' => $this->userDisplayNames[$uid],
+ 'name' => $this->userManager->getDisplayName($uid) ?? $uid,
];
}
/**
- * @param string $uid
- * @return string
- */
- protected function getUserDisplayName(string $uid): string {
- $user = $this->userManager->get($uid);
- if ($user instanceof IUser) {
- return $user->getDisplayName();
- }
- return $uid;
- }
-
- /**
* @param string $gid
* @return array
*/
diff --git a/apps/dav/tests/unit/CalDAV/Activity/Provider/BaseTest.php b/apps/dav/tests/unit/CalDAV/Activity/Provider/BaseTest.php
index 21cafee4f88..9e1e02189f5 100644
--- a/apps/dav/tests/unit/CalDAV/Activity/Provider/BaseTest.php
+++ b/apps/dav/tests/unit/CalDAV/Activity/Provider/BaseTest.php
@@ -160,41 +160,4 @@ class BaseTest extends TestCase {
'name' => $gid,
], $this->invokePrivate($this->provider, 'generateGroupParameter', [$gid]));
}
-
- public function dataGenerateUserParameter() {
- $u1 = $this->createMock(IUser::class);
- $u1->expects($this->any())
- ->method('getDisplayName')
- ->willReturn('User 1');
- return [
- ['u1', 'User 1', $u1],
- ['u2', 'u2', null],
- ];
- }
-
- /**
- * @dataProvider dataGenerateUserParameter
- * @param string $uid
- * @param string $displayName
- * @param IUser|null $user
- */
- public function testGenerateUserParameter(string $uid, string $displayName, ?IUser $user) {
- $this->userManager->expects($this->once())
- ->method('get')
- ->with($uid)
- ->willReturn($user);
-
- $this->assertEquals([
- 'type' => 'user',
- 'id' => $uid,
- 'name' => $displayName,
- ], $this->invokePrivate($this->provider, 'generateUserParameter', [$uid]));
-
- // Test caching (only 1 user manager invocation allowed)
- $this->assertEquals([
- 'type' => 'user',
- 'id' => $uid,
- 'name' => $displayName,
- ], $this->invokePrivate($this->provider, 'generateUserParameter', [$uid]));
- }
}