Skip to content

Commit e557ecf

Browse files
committed
fix: populate cache when creating user
Signed-off-by: Robin Appelman <robin@icewind.nl>
1 parent 7d98194 commit e557ecf

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

lib/UserBackend.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class UserBackend extends ABackend implements
3838
IGetRealUIDBackend,
3939
IPasswordHashBackend {
4040

41+
/** @var CappedMemoryCache<array{'uid': string, 'displayname': ?string}> */
4142
private CappedMemoryCache $cache;
4243

4344
private bool $allowListing = true;
@@ -73,8 +74,9 @@ public function createUser(string $uid, string $password): bool {
7374

7475
$result = $qb->executeStatement();
7576

76-
// Clear cache
77-
unset($this->cache[$uid]);
77+
$this->cache[$uid] = [];
78+
$this->cache[$uid]['uid'] = $uid;
79+
$this->cache[$uid]['displayname'] = null;
7880

7981
return (bool)$result;
8082
}
@@ -109,7 +111,11 @@ public function setInitialEmail(string $uid, string $email): bool {
109111
$query->update('guests_users')
110112
->set('email', $query->createNamedParameter($email))
111113
->where($query->expr()->eq('uid_lower', $query->createNamedParameter(mb_strtolower($uid))));
112-
return (bool)$query->executeStatement();
114+
$result = (bool)$query->executeStatement();
115+
if ($result && isset($this->cache[$uid])) {
116+
$this->cache[$email] = $this->cache[$uid];
117+
}
118+
return $result;
113119
}
114120

115121
/**

0 commit comments

Comments
 (0)