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

Cache MX and A server lookups #256

Merged
merged 6 commits into from
Nov 3, 2024

Conversation

ianbayne
Copy link
Contributor

Closes #179.

@ianbayne ianbayne force-pushed the new/cache-domain-dns-and-mx-checks branch from a12df3a to ec38120 Compare October 16, 2024 13:52
@ianbayne ianbayne changed the title [WIP] Cache mx and a server lookups [WIP] Cache MX and A server lookups Oct 16, 2024
@ianbayne ianbayne marked this pull request as ready for review October 21, 2024 12:56
@ianbayne
Copy link
Contributor Author

Hi @micke, please let me know if this isn't what you had in mind. Happy to follow a different path 👍

@ianbayne ianbayne changed the title [WIP] Cache MX and A server lookups Cache MX and A server lookups Oct 21, 2024
@micke
Copy link
Owner

micke commented Oct 23, 2024

This is a good start, i'm however thinking that we might need to consider two factors still:

  1. The cache growing to be too big.
  2. The cache going stale, i think it would be really important for us to take the DNS records TTL into consideration to make sure that we don't cache the MX servers for too long.

@ianbayne
Copy link
Contributor Author

Thanks for the feedback, @micke. Any thoughts on a maximum size for the cache?

@ianbayne ianbayne marked this pull request as draft October 26, 2024 02:58
@ianbayne ianbayne changed the title Cache MX and A server lookups [WIP] Cache MX and A server lookups Oct 26, 2024
@ianbayne ianbayne force-pushed the new/cache-domain-dns-and-mx-checks branch 4 times, most recently from 7e2944a to 4bf848d Compare October 26, 2024 04:33
@ianbayne
Copy link
Contributor Author

ianbayne commented Oct 26, 2024

This is a good start, i'm however thinking that we might need to consider two factors still:

  1. The cache growing to be too big.

  2. The cache going stale, i think it would be really important for us to take the DNS records TTL into consideration to make sure that we don't cache the MX servers for too long.

@micke, I've gone ahead and pushed up some additional commits that should meet these requirements. I've arbitrarily selected 1,000 as the max cache size. Please feel free to suggest a different value! Also, a lot of this code could be DRY-ed up; if you like the implementation I’ll do so.

@ianbayne ianbayne marked this pull request as ready for review October 26, 2024 04:35
@ianbayne ianbayne changed the title [WIP] Cache MX and A server lookups Cache MX and A server lookups Oct 26, 2024
@micke
Copy link
Owner

micke commented Oct 26, 2024

@ianbayne Great work! What do you think about maybe moving the caching logic to it's own class?

@ianbayne
Copy link
Contributor Author

@ianbayne Great work! What do you think about maybe moving the caching logic to it's own class?

Thanks! Sure, works for me. I’ll get on it when I’ve next got some spare time 👍

@ianbayne ianbayne force-pushed the new/cache-domain-dns-and-mx-checks branch 3 times, most recently from e5e986c to 519ee1c Compare November 2, 2024 05:07
@ianbayne ianbayne force-pushed the new/cache-domain-dns-and-mx-checks branch from 519ee1c to a3575b9 Compare November 2, 2024 05:13
@@ -5,6 +5,7 @@
require 'rspec-benchmark'
RSpec.configure do |config|
config.include RSpec::Benchmark::Matchers
config.default_formatter = 'doc'
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 prefer this personally, but feel free to delete if you'd rather not have it.

@@ -0,0 +1,37 @@
module ValidEmail2
class DnsRecordsCache
Copy link
Contributor Author

Choose a reason for hiding this comment

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

DnsRecordsCache

Definitely open to different/better naming for this!

@ianbayne
Copy link
Contributor Author

ianbayne commented Nov 2, 2024

@ianbayne Great work! What do you think about maybe moving the caching logic to it's own class?

This should be ready for another review, @micke. Lots of stubbing going on in the tests, but hopefully not an excessive amount.

@mscrivo
Copy link
Contributor

mscrivo commented Nov 2, 2024

This is great stuff @ianbayne! One other optimization I can see being useful here is to move the setup of Resolv::DNS::Config into these functions where it's actually used. We're seeing a perf problem with heavy use of this gem where it's spending a lot of time setting up this config even though we're only calling valid? and never actually using it.

@ianbayne
Copy link
Contributor Author

ianbayne commented Nov 2, 2024

Sure @mscrivo, happy to make that change. See commit eb794f2.

@micke, please let me know if you'd prefer this commit to be part of a separate PR.

@micke micke merged commit 72115ec into micke:main Nov 3, 2024
6 checks passed
@micke
Copy link
Owner

micke commented Nov 3, 2024

@ianbayne huge thank you for this! Great work!

@ianbayne ianbayne deleted the new/cache-domain-dns-and-mx-checks branch November 3, 2024 13:24
@ianbayne
Copy link
Contributor Author

ianbayne commented Nov 3, 2024

@ianbayne huge thank you for this! Great work!

Thanks, @micke! Was a fun feature and I learned a lot.

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.

Caching of domain dns/mx check
3 participants