Skip to content

Commit

Permalink
Prevent UserCleanupScheduler from overwhelming streaming (#25519)
Browse files Browse the repository at this point in the history
  • Loading branch information
ThisIsMissEm committed Jun 20, 2023
1 parent dd07393 commit 3a91603
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
18 changes: 17 additions & 1 deletion app/services/remove_status_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class RemoveStatusService < BaseService
# @option [Boolean] :immediate
# @option [Boolean] :preserve
# @option [Boolean] :original_removed
# @option [Boolean] :skip_streaming
def call(status, **options)
@payload = Oj.dump(event: :delete, payload: status.id.to_s)
@status = status
Expand Down Expand Up @@ -52,6 +53,9 @@ def call(status, **options)

private

# The following FeedManager calls all do not result in redis publishes for
# streaming, as the `:update` option is false

def remove_from_self
FeedManager.instance.unpush_from_home(@account, @status)
end
Expand All @@ -75,6 +79,8 @@ def remove_from_mentions
# followers. Here we send a delete to actively mentioned accounts
# that may not follow the account

return if skip_streaming?

@status.active_mentions.find_each do |mention|
redis.publish("timeline:#{mention.account_id}", @payload)
end
Expand Down Expand Up @@ -103,7 +109,7 @@ def remove_reblogs
# without us being able to do all the fancy stuff

@status.reblogs.rewhere(deleted_at: [nil, @status.deleted_at]).includes(:account).reorder(nil).find_each do |reblog|
RemoveStatusService.new.call(reblog, original_removed: true)
RemoveStatusService.new.call(reblog, original_removed: true, skip_streaming: skip_streaming?)
end
end

Expand All @@ -114,6 +120,8 @@ def remove_from_hashtags

return unless @status.public_visibility?

return if skip_streaming?

@status.tags.map(&:name).each do |hashtag|
redis.publish("timeline:hashtag:#{hashtag.mb_chars.downcase}", @payload)
redis.publish("timeline:hashtag:#{hashtag.mb_chars.downcase}:local", @payload) if @status.local?
Expand All @@ -123,13 +131,17 @@ def remove_from_hashtags
def remove_from_public
return unless @status.public_visibility?

return if skip_streaming?

redis.publish('timeline:public', @payload)
redis.publish(@status.local? ? 'timeline:public:local' : 'timeline:public:remote', @payload)
end

def remove_from_media
return unless @status.public_visibility?

return if skip_streaming?

redis.publish('timeline:public:media', @payload)
redis.publish(@status.local? ? 'timeline:public:local:media' : 'timeline:public:remote:media', @payload)
end
Expand All @@ -143,4 +155,8 @@ def remove_media
def permanently?
@options[:immediate] || !(@options[:preserve] || @status.reported?)
end

def skip_streaming?
!!@options[:skip_streaming]
end
end
2 changes: 1 addition & 1 deletion app/workers/scheduler/user_cleanup_scheduler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def clean_unconfirmed_accounts!
def clean_discarded_statuses!
Status.unscoped.discarded.where('deleted_at <= ?', 30.days.ago).find_in_batches do |statuses|
RemovalWorker.push_bulk(statuses) do |status|
[status.id, { 'immediate' => true }]
[status.id, { 'immediate' => true, 'skip_streaming' => true }]
end
end
end
Expand Down

0 comments on commit 3a91603

Please sign in to comment.