Skip to content

Use eachById in mailbox:clean #137

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

cwilby
Copy link

@cwilby cwilby commented Jun 14, 2025

I added mailbox:clean to an application that has been using this package for several years, and noticed that older emails weren't being cleared out unless I ran the command multiple times.

Reading the command, I noticed it used chunk when deleting records. The problem with chunk in this context is that it uses offset/limit pagination under the hood. As rows are deleted in each chunk, the remaining rows shift, causing the next chunk to skip some records. This results in incomplete deletions unless the command is repeatedly executed.

To verify the issue, I modified CleanEmailsTest to create 200 records instead of 60, which caused the test to fail due to records being skipped.

To fix this, the command now uses eachById, which paginates based on primary key rather than offset. This avoids skipping rows during deletion, since it always continues from the last seen ID, not a shifting offset.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant