about summary refs log tree commit diff
path: root/lib/tasks/monsterfork.rake
blob: eeddeb3df92213ecf529c4c52f126ec20862905d (plain) (blame)
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
27
28
29
30
31
32
33
34
# frozen_string_literal: true

namespace :monsterfork do
  desc "Re-apply all users' filters to their home and list timelines."
  task reapply_filters: :environment do
    Account.local.find_each do |account|
      Rails.logger.info("Re-applying filters for: #{account.username}")
      Redis.current.del("filtered_statuses:#{account.id}")
      FilterFeedsWorker.perform_async(account.id)
      sleep 1
      while Sidekiq::Queue.new.size > 5
        sleep 1
      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