Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Mar 5, 2024

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
36 of 37 checks passed
@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