domain_materializable.rb 665 B

1234567891011121314151617181920212223242526
  1. # frozen_string_literal: true
  2. module DomainMaterializable
  3. extend ActiveSupport::Concern
  4. include Redisable
  5. included do
  6. after_create_commit :refresh_instances_view
  7. end
  8. def refresh_instances_view
  9. return if domain.nil? || Instance.exists?(domain: domain)
  10. Instance.refresh
  11. count_unique_subdomains!
  12. end
  13. def count_unique_subdomains!
  14. second_and_top_level_domain = PublicSuffix.domain(domain, ignore_private: true)
  15. with_redis do |redis|
  16. redis.pfadd("unique_subdomains_for:#{second_and_top_level_domain}", domain)
  17. redis.expire("unique_subdomains_for:#{second_and_top_level_domain}", 1.minute.seconds)
  18. end
  19. end
  20. end