mirror of
https://github.com/lunaisnotaboy/mastodon.git
synced 2024-09-11 20:57:44 +00:00
* fix(status): remove send usage for private unlink_from_conversations - make unlink_from_conversations public method - rename unlink_from_conversations to unlink_from_conversations! - fix send call on private method in statuses_vacuum and batched_remove_status_service * fix(feeds_vacuum): replace find_in_batches with in_batches because active record query results should be a little more efficient than itterating with map and each. Postgres can grasp such lists of ids much quicker than ruby can. Will probably make allmost no difference, but cannot hurt either.
45 lines
1.1 KiB
Ruby
45 lines
1.1 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
class Vacuum::StatusesVacuum
|
|
include Redisable
|
|
|
|
def initialize(retention_period)
|
|
@retention_period = retention_period
|
|
end
|
|
|
|
def perform
|
|
vacuum_statuses! if @retention_period.present?
|
|
end
|
|
|
|
private
|
|
|
|
def vacuum_statuses!
|
|
statuses_scope.in_batches do |statuses|
|
|
# Side-effects not covered by foreign keys, such
|
|
# as the search index, must be handled first.
|
|
statuses.direct_visibility
|
|
.includes(mentions: :account)
|
|
.find_each(&:unlink_from_conversations!)
|
|
remove_from_search_index(statuses.ids) if Chewy.enabled?
|
|
|
|
# Foreign keys take care of most associated records for us.
|
|
# Media attachments will be orphaned.
|
|
statuses.delete_all
|
|
end
|
|
end
|
|
|
|
def statuses_scope
|
|
Status.unscoped.kept
|
|
.joins(:account).merge(Account.remote)
|
|
.where('statuses.id < ?', retention_period_as_id)
|
|
end
|
|
|
|
def retention_period_as_id
|
|
Mastodon::Snowflake.id_at(@retention_period.ago, with_random: false)
|
|
end
|
|
|
|
def remove_from_search_index(status_ids)
|
|
with_redis { |redis| redis.sadd('chewy:queue:StatusesIndex', status_ids) }
|
|
end
|
|
end
|