Skip to content

Commit 0c89954

Browse files
authored
Merge pull request #23215 from nextcloud/bugfix/noid/only-run-the-query-once
Only run the query to get the account data once
2 parents e0372e3 + ac59f23 commit 0c89954

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

lib/private/Accounts/AccountManager.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -134,19 +134,21 @@ public function deleteUser(IUser $user) {
134134
public function getUser(IUser $user) {
135135
$uid = $user->getUID();
136136
$query = $this->connection->getQueryBuilder();
137-
$query->select('data')->from($this->table)
137+
$query->select('data')
138+
->from($this->table)
138139
->where($query->expr()->eq('uid', $query->createParameter('uid')))
139140
->setParameter('uid', $uid);
140-
$query->execute();
141-
$result = $query->execute()->fetchAll();
141+
$result = $query->execute();
142+
$accountData = $result->fetchAll();
143+
$result->closeCursor();
142144

143-
if (empty($result)) {
145+
if (empty($accountData)) {
144146
$userData = $this->buildDefaultUserRecord($user);
145147
$this->insertNewUser($user, $userData);
146148
return $userData;
147149
}
148150

149-
$userDataArray = json_decode($result[0]['data'], true);
151+
$userDataArray = json_decode($accountData[0]['data'], true);
150152
$jsonError = json_last_error();
151153
if ($userDataArray === null || $userDataArray === [] || $jsonError !== JSON_ERROR_NONE) {
152154
$this->logger->critical("User data of $uid contained invalid JSON (error $jsonError), hence falling back to a default user record");

0 commit comments

Comments
 (0)