From fff840ac4f88c12cd484af0cd730a913e92e6865 Mon Sep 17 00:00:00 2001 From: Christoph Wurst Date: Thu, 29 Feb 2024 08:20:19 +0100 Subject: [PATCH] fix(db): Avoid dirty read for local message updates Signed-off-by: Christoph Wurst --- lib/Db/LocalMessageMapper.php | 6 +++--- tests/Integration/Db/LocalMessageMapperTest.php | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/Db/LocalMessageMapper.php b/lib/Db/LocalMessageMapper.php index fd8db38586..54fcc67ae5 100644 --- a/lib/Db/LocalMessageMapper.php +++ b/lib/Db/LocalMessageMapper.php @@ -256,14 +256,14 @@ public function updateWithRecipients(LocalMessage $message, array $to, array $cc $message = $this->update($message); $this->recipientMapper->updateRecipients($message->getId(), $message->getRecipients(), $to, $cc, $bcc); + $recipients = $this->recipientMapper->findByLocalMessageId($message->getId()); + $message->setRecipients($recipients); $this->db->commit(); + return $message; } catch (Throwable $e) { $this->db->rollBack(); throw $e; } - $recipients = $this->recipientMapper->findByLocalMessageId($message->getId()); - $message->setRecipients($recipients); - return $message; } public function deleteWithRecipients(LocalMessage $message): void { diff --git a/tests/Integration/Db/LocalMessageMapperTest.php b/tests/Integration/Db/LocalMessageMapperTest.php index 2865f00d4d..274432e6de 100644 --- a/tests/Integration/Db/LocalMessageMapperTest.php +++ b/tests/Integration/Db/LocalMessageMapperTest.php @@ -174,7 +174,7 @@ public function testSaveWithRecipient(): void { $this->assertCount(1, $row->getRecipients()); } - public function testUpdateWithRecipient(): void { + public function testUpdateWithRecipients(): void { $results = $this->mapper->getAllForUser($this->account->getUserId()); $this->assertEmpty($results[0]->getRecipients()); // cleanup