Skip to content

Commit 5157f10

Browse files
Kocbackportbot[bot]
authored andcommitted
fix: Remove user memoization
Signed-off-by: Kostiantyn Miakshyn <molodchick@gmail.com>
1 parent ce36c15 commit 5157f10

2 files changed

Lines changed: 5 additions & 22 deletions

File tree

lib/CurrentUser.php

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,6 @@
1717

1818
class CurrentUser {
1919

20-
/** @var string|null */
21-
protected $identifier = null;
22-
/** @var string|false|null */
23-
protected $cloudId = false;
24-
/** @var string|false|null */
25-
protected $sessionUser = false;
26-
2720
public function __construct(
2821
protected readonly IUserSession $userSession,
2922
protected readonly IRequest $request,
@@ -46,25 +39,21 @@ public function getUserIdentifier(): string {
4639

4740
$uid = $this->getUID();
4841
if ($uid !== null) {
49-
$this->identifier = $uid;
50-
return $this->identifier;
42+
return $uid;
5143
}
5244

5345
$cloudId = $this->getCloudIDFromToken();
5446
if ($cloudId !== null) {
55-
$this->identifier = $cloudId;
56-
return $this->identifier;
47+
return $cloudId;
5748
}
5849

5950
$nickname = htmlspecialchars($this->request->getHeader('X-NC-Nickname'));
6051
if ($nickname !== '') {
61-
$this->identifier = $nickname . ' (' . $this->l10nFactory->get('comments')->t('remote user') . ')';
62-
return $this->identifier;
52+
return $nickname . ' (' . $this->l10nFactory->get('comments')->t('remote user') . ')';
6353
}
6454

6555
// Nothing worked, fallback to empty string
66-
$this->identifier = '';
67-
return $this->identifier;
56+
return '';
6857
}
6958

7059
/**
@@ -79,8 +68,7 @@ public function getUID(): ?string {
7968
$this->sessionUser = null;
8069
}
8170
}
82-
83-
return $this->sessionUser;
71+
return null;
8472
}
8573

8674
/**
@@ -95,8 +83,6 @@ public function getCloudId(): ?string {
9583
$this->cloudId = $this->getCloudIDFromToken();
9684
}
9785
}
98-
99-
return $this->cloudId;
10086
}
10187

10288
/**

tests/CurrentUserTest.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ public static function dataGetUserIdentifier(): array {
8787
[null, null, null, ''],
8888
[null, 'uid', '-1', 'uid'],
8989
[null, null, 'token', 'token'],
90-
['cached', -1, -1, 'cached'],
9190
];
9291
}
9392

@@ -98,8 +97,6 @@ public function testGetUserIdentifier(?string $cachedIdentifier, string|int|null
9897
'getCloudIDFromToken',
9998
]);
10099

101-
self::invokePrivate($instance, 'identifier', [$cachedIdentifier]);
102-
103100
$instance->expects($uidResult !== -1 ? $this->once() : $this->never())
104101
->method('getUID')
105102
->willReturn($uidResult);

0 commit comments

Comments
 (0)