2020-12-14 09:06:34 +01:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module DomainMaterializable
|
|
|
|
extend ActiveSupport::Concern
|
|
|
|
|
2022-12-15 19:21:17 +01:00
|
|
|
include Redisable
|
|
|
|
|
2020-12-14 09:06:34 +01:00
|
|
|
included do
|
|
|
|
after_create_commit :refresh_instances_view
|
|
|
|
end
|
|
|
|
|
|
|
|
def refresh_instances_view
|
2022-12-15 19:21:17 +01:00
|
|
|
return if domain.nil? || Instance.exists?(domain: domain)
|
|
|
|
|
|
|
|
Instance.refresh
|
|
|
|
count_unique_subdomains!
|
|
|
|
end
|
|
|
|
|
|
|
|
def count_unique_subdomains!
|
|
|
|
second_and_top_level_domain = PublicSuffix.domain(domain, ignore_private: true)
|
|
|
|
with_redis do |redis|
|
|
|
|
redis.pfadd("unique_subdomains_for:#{second_and_top_level_domain}", domain)
|
|
|
|
redis.expire("unique_subdomains_for:#{second_and_top_level_domain}", 1.minute.seconds)
|
|
|
|
end
|
2020-12-14 09:06:34 +01:00
|
|
|
end
|
|
|
|
end
|