about summary refs log tree commit diff
path: root/app/models/concerns/domain_materializable.rb
diff options
context:
space:
mode:
authorClaire <claire.github-309c@sitedethib.com>2022-12-04 21:23:19 +0100
committerGitHub <noreply@github.com>2022-12-04 21:23:19 +0100
commitfe523a304520a09f6371f45bd63b9e8988776c03 (patch)
tree3e8d595b1cfe797db6d5f8c36425f52b82d5798a /app/models/concerns/domain_materializable.rb
parentf4879c4481ff4fd487bc1bfb1a48aa252960b2a3 (diff)
Fix unbounded recursion in account discovery (#1994)
* Fix trying to fetch posts from other users when fetching featured posts

* Rate-limit discovery of new subdomains

* Put a limit on recursively discovering new accounts
Diffstat (limited to 'app/models/concerns/domain_materializable.rb')
-rw-r--r--app/models/concerns/domain_materializable.rb16
1 files changed, 15 insertions, 1 deletions
diff --git a/app/models/concerns/domain_materializable.rb b/app/models/concerns/domain_materializable.rb
index 88337f8c0..798672213 100644
--- a/app/models/concerns/domain_materializable.rb
+++ b/app/models/concerns/domain_materializable.rb
@@ -3,11 +3,25 @@
 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