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

Offer the possibility to keep a finite number of mails #375

Conversation

marcmillien
Copy link
Contributor

@marcmillien marcmillien commented Apr 20, 2018

Context

When mailcatcher receives thousand of mails per day the web interface is very slow and can take several minutes to appear.

Description

This PR adds an option that allows to specify a max number of mail to keep, so mailcatcher is responsive when people access it even in case of high catching trafic.

References

Requires #374 before merge

@marcmillien marcmillien force-pushed the offer-the_possibility_to_keep_a_finite_number_of_mails branch 2 times, most recently from 3da0505 to 74cba52 Compare April 20, 2018 08:16
@marcmillien marcmillien force-pushed the offer-the_possibility_to_keep_a_finite_number_of_mails branch from 74cba52 to 1c6781e Compare April 20, 2018 08:43
Copy link

@kbrock kbrock left a comment

Choose a reason for hiding this comment

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

Do we really need the first 2 commits?

Seems this would be easier to merge if it didn't have the dependency.

Other than that - LGTM

I'm not a committer - so please take my opinions with a grain of salt

@@ -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 == -1
Copy link

Choose a reason for hiding this comment

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

maybe return if max_mail_to_keep <= 0

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍 I change this

@marcmillien
Copy link
Contributor Author

Do we really need the first 2 commits?

Good catch, I fix it :)

Signed-off-by: Marc Millien <marc.millien@gmail.com>
@marcmillien marcmillien force-pushed the offer-the_possibility_to_keep_a_finite_number_of_mails branch from 1c6781e to e884fe4 Compare July 9, 2018 14:51
@pbielicki
Copy link

Can we get this merged please? @sj26

Copy link

@kbrock kbrock left a comment

Choose a reason for hiding this comment

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

I did have one suggestion for performance.

But to be honest, it probably only will matter with a very big table.
And I'm not sure how much time you should spend polishing this PR

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 ?)"
Copy link

Choose a reason for hiding this comment

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

Are the right records getting deleted here?
Should this delete the same rows as the previous line?

DELETE from message_part
WHERE message_id NOT IN (SELECT id from message ORDER BY created_at DESC LIMIT ?)

(or ORDER BY id if the previous ORDER BY change was made)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You are right, I change this :).


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 ?)"
Copy link

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 we ORDER 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

cluesque pushed a commit to cluesque/mailcatcher that referenced this pull request Nov 17, 2019
inspired by (stolen from) sj26#375
cluesque pushed a commit to cluesque/mailcatcher that referenced this pull request Nov 17, 2019
inspired by (stolen from) sj26#375
@lbenedetto lbenedetto mentioned this pull request Nov 26, 2019
@lbenedetto
Copy link

Over a year later and still not merged. Is there a reason for this not to be merged, or is the project abandoned?

@sj26
Copy link
Owner

sj26 commented Nov 28, 2019

Thank you for your contribution @marcmillien! I'm truly sorry I haven't commented here yet.

I like this feature. I didn't merge it because every time I looked at it, I realised it was predicated on a bunch of testing and docker changes, and teasing them apart was tricky enough to become "later" problem, and then later never came.

Honestly this project is in a maintenance-ish mode — it works, and I'll keep it working, but I consider it feature-complete, and most of the things I would like to address require a complete rewrite which is a bit too monumental. Every time I come to look at this repo, I'm reminded of this, too.

So, for right now, I'll rebase this, make a few adjustments, and then merge it.

sj26 added a commit that referenced this pull request Nov 28, 2019
…p_a_finite_number_of_mails

Offer the possibility to keep a finite number of mails
@sj26
Copy link
Owner

sj26 commented Nov 28, 2019

This has been rebased and merged — thanks!

@sj26 sj26 closed this Nov 28, 2019
@sj26
Copy link
Owner

sj26 commented Jan 22, 2020

Please try v0.8.0.beta1 via gem install --pre mailcatcher and let me know how you go. :-)

@sj26
Copy link
Owner

sj26 commented Jul 20, 2021

This is shipped in the latest version, v0.8.0.

gem install mailcatcher

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.

5 participants