disposable_mail
disposable_mail copied to clipboard
Update blocklist + improve performance greatly (200 times faster :rocket: )
Hello :wave:
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 :rocket:) by using a Set instead of Array +split
instead of regexp. :warning: 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 :heavy_check_mark: green build)
- The
#include?
method now really returns a Boolean as explained in the readme (instead of String ornil
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 #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)
Great job ;)
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 :pray:
@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.
@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.
@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.
@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.
@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?
@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
# ...