-
Notifications
You must be signed in to change notification settings - Fork 574
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
Offer the possibility to keep a finite number of mails #375
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -157,4 +157,13 @@ def delete_message!(message_id) | |
@delete_messages_query.execute(message_id) and | ||
@delete_message_parts_query.execute(message_id) | ||
end | ||
|
||
def delete_older_messages!(max_mail_to_keep = MailCatcher::options[:max_mail_to_keep]) | ||
return if max_mail_to_keep <= 0 | ||
@delete_older_messages_query ||= db.prepare "DELETE FROM message WHERE id NOT IN (SELECT id FROM message ORDER BY created_at DESC LIMIT ?)" | ||
@delete_older_message_parts_query ||= db.prepare "DELETE FROM message_part WHERE id NOT IN (SELECT id FROM message_part ORDER BY created_at DESC LIMIT ?)" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are the right records getting deleted here? DELETE from message_part
WHERE message_id NOT IN (SELECT id from message ORDER BY created_at DESC LIMIT ?) (or There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You are right, I change this :). |
||
|
||
@delete_older_messages_query.execute(max_mail_to_keep) and | ||
@delete_older_message_parts_query.execute(max_mail_to_keep) | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since
id
is the primary key, it has an index. Can weORDER BY id
?Also, dealing with just a single indexed column, most databases run much quicker, avoiding hitting the data page altogether.
It may be just a marginal savings though. So feel free to ignore