From 00e65a77df600330c4ae694616fb185e15b8835f Mon Sep 17 00:00:00 2001 From: Emelia Smith Date: Tue, 20 Jun 2023 18:04:35 +0200 Subject: [PATCH] Prevent UserCleanupScheduler from overwhelming streaming (#25519) --- app/services/remove_status_service.rb | 18 +++++++++++++++++- .../scheduler/user_cleanup_scheduler.rb | 2 +- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/app/services/remove_status_service.rb b/app/services/remove_status_service.rb index 8dc521eedfb..f039ab47603 100644 --- a/app/services/remove_status_service.rb +++ b/app/services/remove_status_service.rb @@ -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 @@ -50,6 +51,9 @@ class RemoveStatusService < BaseService 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 @@ -73,6 +77,8 @@ class RemoveStatusService < BaseService # 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 @@ -101,7 +107,7 @@ class RemoveStatusService < BaseService # without us being able to do all the fancy stuff @status.reblogs.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 @@ -112,6 +118,8 @@ class RemoveStatusService < BaseService 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? @@ -121,6 +129,8 @@ class RemoveStatusService < BaseService 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 @@ -128,6 +138,8 @@ class RemoveStatusService < BaseService 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 @@ -141,4 +153,8 @@ class RemoveStatusService < BaseService def permanently? @options[:immediate] || !(@options[:preserve] || @status.reported?) end + + def skip_streaming? + !!@options[:skip_streaming] + end end diff --git a/app/workers/scheduler/user_cleanup_scheduler.rb b/app/workers/scheduler/user_cleanup_scheduler.rb index df566a18c2c..77715ac1d71 100644 --- a/app/workers/scheduler/user_cleanup_scheduler.rb +++ b/app/workers/scheduler/user_cleanup_scheduler.rb @@ -31,7 +31,7 @@ class Scheduler::UserCleanupScheduler 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