Skip to content

fix(db): Avoid dirty reads while deleting messages by uid#9423

Merged
st3iny merged 1 commit intomainfrom
fix/db/dirty-read-message-delete-by-uid
Mar 5, 2024
Merged

fix(db): Avoid dirty reads while deleting messages by uid#9423
st3iny merged 1 commit intomainfrom
fix/db/dirty-read-message-delete-by-uid

Conversation

@ChristophWurst
Copy link
Member

  1. Instead of SELECT all data into memory and run a second DELETE query, use a sub query.
  2. Instead of looking up IDs for UIDs and deleting by ID, delete by UID directly.

This method was prone to dirty reads before. Now there are only write queries.

Ref nextcloud/groupware#24

How to test

  1. Set up an account in Mail and a second client
  2. Delete messages in the other client
  3. Sync Mail

Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>

foreach (array_chunk($uids, 1000) as $chunk) {
$messageIdQuery->setParameter('uids', $chunk, IQueryBuilder::PARAM_INT_ARRAY);
$cursor = $messageIdQuery->executeQuery();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original implementation of deleteByUid did use a sub query too: #4663. Then #4947 added an intermediate fetch. @miaulalala do you remember why this was done?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most likely because I ran into the usual subquery issues (where to put the brackets) and didn't know how to fix it back then.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good. Then this change is safe :)

Copy link
Member

@st3iny st3iny left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested and works. Logs were clean.

@st3iny st3iny merged commit 99409c6 into main Mar 5, 2024
@st3iny st3iny deleted the fix/db/dirty-read-message-delete-by-uid branch March 5, 2024 21:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants