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

Update blocklist + improve performance greatly (200 times faster 🚀 ) #7

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

Conversation

jarthod
Copy link

@jarthod jarthod commented May 7, 2021

Hello 👋

Thanks for this nice gem!

I just started using it and saw a couple things to improve/update so here is a little PR with the following improvements:

  • Updated the blocklist to latest version of disposable-email-domains
  • Improve performance greatly (#include? is now 200 times faster 🚀) by using a Set instead of Array + split instead of regexp. ⚠️ This is a slightly breaking change as the list is not longer an array but most method will still work, this is still better I believe. Please see below the benchmark comparing original vs new version.
  • Update outdated ruby version in travis.yml (here is the ✔️ green build)
  • The #include? method now really returns a Boolean as explained in the readme (instead of String or nil currently)
  • The list can now easily be edited to add missing domains or remove some (I also updated the readme with instructions and added a test for this case)
  • I also added support for subdomains, if a providers supports multiple subdomains, the gem will find now find it in the list.
  • Improved the rake task to automatically pull the submodule and update the ruby file
  • I bumped the version to 0.2 but let me know if you prefer something else
  • I also added the fix for Ruby 3 from fix adding error on ruby 3.0 #8

For people who wants to use this branch before it is merged, use this in your Gemfile:

gem 'disposable_mail', github: 'jarthod/disposable_mail', branch: 'update-list-improve-performance' # https://github.com/oesgalha/disposable_mail/pull/7

Benchmark results:

require './lib/disposable_mail/disposable'
require 'benchmark'

N = 10
emails = DisposableMail.list.map {|domain| "test@#{domain}"}

Benchmark.bmbm do |x|
  x.report("original") { N.times { emails.each { |e| DisposableMail.include?(e) } } }
  x.report("new") { N.times { emails.each { |e| DisposableMail.include2?(e) } } }
end

# > ruby benchmark.rb
# Rehearsal --------------------------------------------
# original   2.306290   0.003521   2.309811 (  2.309856)
# new        0.011054   0.000010   0.011064 (  0.011065)
# ----------------------------------- total: 2.320875sec

#                user     system      total        real
# original   2.209011   0.000000   2.209011 (  2.209096)
# new        0.010861   0.000000   0.010861 (  0.010884)

@jarthod jarthod mentioned this pull request May 7, 2021
@Tioneb12
Copy link

Great job ;)

@jarthod jarthod changed the title Update blocklist + improve performance greatly (200 times faster 🚀) Update blocklist + improve performance greatly (200 times faster 🚀 ) May 18, 2021
@jarthod jarthod mentioned this pull request May 20, 2021
@jarthod
Copy link
Author

jarthod commented Aug 5, 2022

For the record I just added the ruby 3 fix from #8 and #9 (thanks @mkrajewski90 and @Annedj).
I've been using this branch successfully for more than a year, any way to get this merged @oesgalha?
Thanks 🙏

@tbsvttr
Copy link

tbsvttr commented Apr 6, 2023

@jarthod Thanks for your work! This branch sadly seems to cause problems with Rails 6.1.X that were not present with Rails 6.0.X.

@jarthod
Copy link
Author

jarthod commented Apr 6, 2023

@tbsvttr what problem? I am currently using it on Rails 7.0 and have been using it on Rails 6.1 for a while before that.

@tbsvttr
Copy link

tbsvttr commented Apr 6, 2023

@jarthod errors.add now only takes two parameters. Blew me up as I updated from Rails 6.0.X to Rails 6.1.X. Monkey patched it.

@jarthod
Copy link
Author

jarthod commented Apr 6, 2023

@tbsvttr ah ok, I'm using Mongoid instead of AR so maybe they probably kept the compatibility there. Can you share your monkeypatch for others maybe? If it doesn't break compatibilité with older version I'll update the branch.

@IncSow
Copy link

IncSow commented Nov 16, 2023

@jarthod Where do you usually add the new domains to the existing list? Is it on initalization of the rails app or does it have to be added manually anytime we perform a check?

@jarthod
Copy link
Author

jarthod commented Nov 16, 2023

@IncSow With this branch it can be done at initialization yes, in my case I put it in my user.rb model file (at the top of the file not inside a method so it's only done once) simply because that's where I used it but an initializer will also work fine. Here is what I'm currently adding:

DisposableMail.list.merge %w(cnxingye.com threepp.com mailper.com acrossgracealley.com thichanthit.com tempmailin.com digital10network.com musiccode.me ryteto.me livinginsurance.co.uk onekisspresave.com norwegischlernen.info emailnax.com afia.pro aramask.com camplvad.com clout.wiki consultant.com devsquad.asia duscore.com finews.biz gufum.com hexi.pics introace.com lyft.live merepost.com realremedyblog.com socam.me tutuapp.bid vanturtransfer.com)

class User
# ...

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.

4 participants