Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/mail.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristoph Wurst <christoph@winzerhof-wurst.at>2022-05-16 18:40:02 +0300
committerChristoph Wurst <christoph@winzerhof-wurst.at>2022-05-23 09:58:09 +0300
commit8d497484ce4e66127b6a93d875d177246da6f3ac (patch)
tree4e7c16d0aeca93b7c1fba47b0624acff17720c32
parent396805004ea1da8dc460c743a48b89575ab33ce1 (diff)
Prevent causal read for outbox message and recipient inserts
The message and the recipients are inserted in one transaction but the recipients are read another time outside a transaction. Read-write split database clusters might not be in full sync mode and then reading the recipients gives partial or no results. The insert will assign the primary key value to the recipient entities. Therefore we can skip reading the data. Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
-rw-r--r--lib/Db/LocalMessageMapper.php8
-rw-r--r--lib/Db/RecipientMapper.php3
-rw-r--r--tests/Integration/Service/OutboxServiceIntegrationTest.php4
3 files changed, 7 insertions, 8 deletions
diff --git a/lib/Db/LocalMessageMapper.php b/lib/Db/LocalMessageMapper.php
index d99550ace..79c8ee2f3 100644
--- a/lib/Db/LocalMessageMapper.php
+++ b/lib/Db/LocalMessageMapper.php
@@ -32,6 +32,7 @@ use function array_map;
use OCP\AppFramework\Db\QBMapper;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\IDBConnection;
+use function array_merge;
/**
* @template-extends QBMapper<LocalMessage>
@@ -177,8 +178,11 @@ class LocalMessageMapper extends QBMapper {
$this->db->rollBack();
throw $e;
}
- $recipients = $this->recipientMapper->findByLocalMessageId($message->getId());
- $message->setRecipients($recipients);
+ $message->setRecipients(array_merge(
+ $to,
+ $cc,
+ $bcc,
+ ));
return $message;
}
diff --git a/lib/Db/RecipientMapper.php b/lib/Db/RecipientMapper.php
index 4f5b8bcc0..b2d8c4038 100644
--- a/lib/Db/RecipientMapper.php
+++ b/lib/Db/RecipientMapper.php
@@ -84,9 +84,6 @@ class RecipientMapper extends QBMapper {
* @param Recipient[] $recipients
*/
public function saveRecipients(int $localMessageId, array $recipients): void {
- if (empty($recipients)) {
- return;
- }
foreach ($recipients as $recipient) {
$recipient->setLocalMessageId($localMessageId);
$this->insert($recipient);
diff --git a/tests/Integration/Service/OutboxServiceIntegrationTest.php b/tests/Integration/Service/OutboxServiceIntegrationTest.php
index cbfa17c13..9386f97ea 100644
--- a/tests/Integration/Service/OutboxServiceIntegrationTest.php
+++ b/tests/Integration/Service/OutboxServiceIntegrationTest.php
@@ -160,9 +160,7 @@ class OutboxServiceIntegrationTest extends TestCase {
$this->assertNotEmpty($message->getRecipients());
$this->assertEmpty($message->getAttachments());
- $retrieved->resetUpdatedFields();
- $saved->resetUpdatedFields();
- $this->assertEquals($saved, $retrieved); // Assure both operations are identical
+ self::assertCount(1, $retrieved->getRecipients());
}
public function testSaveAndGetMessages(): void {