about summary refs log tree commit diff
path: root/app/models/concerns/domain_materializable.rb
diff options
context:
space:
mode:
authorStarfall <us@starfall.systems>2022-12-13 09:37:37 -0600
committerStarfall <us@starfall.systems>2022-12-13 09:37:37 -0600
commit9a99643ecd1e11c8763bbcb5c10bd3dfac3dd638 (patch)
treedb93273e38a54683bd41d19f166fe39787b58b67 /app/models/concerns/domain_materializable.rb
parentdc9a63381b3498e915d8334728f0951b231527e6 (diff)
parentb0ef980aa17868f18089233060900aa5d5632863 (diff)
Merge remote-tracking branch 'glitch/main'
Diffstat (limited to 'app/models/concerns/domain_materializable.rb')
-rw-r--r--app/models/concerns/domain_materializable.rb15
1 files changed, 14 insertions, 1 deletions
diff --git a/app/models/concerns/domain_materializable.rb b/app/models/concerns/domain_materializable.rb
index 88337f8c0..0eac6878e 100644
--- a/app/models/concerns/domain_materializable.rb
+++ b/app/models/concerns/domain_materializable.rb
@@ -3,11 +3,24 @@
 module DomainMaterializable
   extend ActiveSupport::Concern
 
+  include Redisable
+
   included do
     after_create_commit :refresh_instances_view
   end
 
   def refresh_instances_view
-    Instance.refresh unless domain.nil? || Instance.where(domain: domain).exists?
+    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