about summary refs log tree commit diff
path: root/lib
diff options
context:
space:
mode:
authormultiple creatures <dev@multiple-creature.party>2020-02-14 05:24:31 -0600
committermultiple creatures <dev@multiple-creature.party>2020-02-14 05:24:31 -0600
commit93bed8dda9657ad65c5ce28e469058e86ec7b17b (patch)
tree42e126fc42788e042e3322affa853370725deac6 /lib
parentd1a887b57a6243dcdbf33f00d4692f25b8f2b270 (diff)
add `rake` task `monsterfork:mark_known_instance_actors`
Diffstat (limited to 'lib')
-rw-r--r--lib/tasks/monsterfork.rake18
1 files changed, 18 insertions, 0 deletions
diff --git a/lib/tasks/monsterfork.rake b/lib/tasks/monsterfork.rake
index 6ca7f54df..eeddeb3df 100644
--- a/lib/tasks/monsterfork.rake
+++ b/lib/tasks/monsterfork.rake
@@ -13,4 +13,22 @@ namespace :monsterfork do
       end
     end
   end
+
+  desc 'Mark known instance actors.'
+  task mark_known_instance_actors: :environment do
+    Rails.logger.info('Gathering known domains...')
+    known_account_ids = Status.where(id: Status.local.reblogs.reorder(nil).select(:reblog_of_id)).reorder(nil).pluck(:account_id) |
+                        Status.where(id: Favourite.select(:status_id)).reorder(nil).pluck(:account_id) |
+                        Account.local.flat_map { |account| account.following_ids | account.follower_ids }
+
+    known_domains = Account.select(:domain).distinct.where(id: known_account_ids).where.not(domain: nil).pluck(:domain)
+
+    known_domains.each do |domain|
+      instance_actor = Account.find_remote(domain, domain)
+      next if instance_actor.nil?
+
+      Rails.logger.info("Marking instance actor known for: #{domain}")
+      instance_actor.update!(known: true)
+    end
+  end
 end