~cytrogen/masto-fe

ref: 937dc42f101be905e3af41b879901a4445b0223a masto-fe/app/models/concerns/domain_materializable.rb -rw-r--r-- 665 bytes
937dc42f — Matt Jankowski Extract methods for file movement in `CLI::Upgrade` (#25120) 2 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# frozen_string_literal: true

module DomainMaterializable
  extend ActiveSupport::Concern

  include Redisable

  included do
    after_create_commit :refresh_instances_view
  end

  def refresh_instances_view
    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
  end
end