2023-08-24 07:40:04 -07:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2023-12-01 03:00:41 -08:00
|
|
|
module Account::StatusesSearch
|
2023-08-24 07:40:04 -07:00
|
|
|
extend ActiveSupport::Concern
|
|
|
|
|
|
|
|
included do
|
|
|
|
after_update_commit :enqueue_update_public_statuses_index, if: :saved_change_to_indexable?
|
|
|
|
after_destroy_commit :enqueue_remove_from_public_statuses_index, if: :indexable?
|
|
|
|
end
|
|
|
|
|
|
|
|
def enqueue_update_public_statuses_index
|
|
|
|
if indexable?
|
|
|
|
enqueue_add_to_public_statuses_index
|
|
|
|
else
|
|
|
|
enqueue_remove_from_public_statuses_index
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def enqueue_add_to_public_statuses_index
|
|
|
|
return unless Chewy.enabled?
|
|
|
|
|
|
|
|
AddToPublicStatusesIndexWorker.perform_async(id)
|
|
|
|
end
|
|
|
|
|
|
|
|
def enqueue_remove_from_public_statuses_index
|
|
|
|
return unless Chewy.enabled?
|
|
|
|
|
|
|
|
RemoveFromPublicStatusesIndexWorker.perform_async(id)
|
|
|
|
end
|
|
|
|
|
|
|
|
def add_to_public_statuses_index!
|
|
|
|
return unless Chewy.enabled?
|
|
|
|
|
2024-03-14 02:31:57 -07:00
|
|
|
statuses.without_reblogs.public_visibility.reorder(nil).find_in_batches do |batch|
|
2023-08-28 06:04:57 -07:00
|
|
|
PublicStatusesIndex.import(batch)
|
2023-08-24 07:40:04 -07:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def remove_from_public_statuses_index!
|
|
|
|
return unless Chewy.enabled?
|
|
|
|
|
|
|
|
PublicStatusesIndex.filter(term: { account_id: id }).delete_all
|
|
|
|
end
|
|
|
|
end
|