Skip to content

Commit

Permalink
Fix inefficiencies in fan-out-on-write service (mastodon#14682)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gargron authored and thenameisnigel-old committed Sep 6, 2020
1 parent 900d27a commit b1d214a
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions app/services/fan_out_on_write_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ class FanOutOnWriteService < BaseService
def call(status)
raise Mastodon::RaceConditionError if status.visibility.nil?

render_anonymous_payload(status)

if status.direct_visibility?
deliver_to_own_conversation(status)
elsif status.limited_visibility?
Expand All @@ -20,6 +18,8 @@ def call(status)

return if status.account.silenced? || !status.public_visibility? || status.reblog?

render_anonymous_payload(status)

deliver_to_hashtags(status)

return if status.reply? && status.in_reply_to_account_id != status.account_id
Expand Down Expand Up @@ -58,8 +58,10 @@ def deliver_to_lists(status)
def deliver_to_mentioned_followers(status)
Rails.logger.debug "Delivering status #{status.id} to limited followers"

FeedInsertWorker.push_bulk(status.mentions.includes(:account).map(&:account).select { |mentioned_account| mentioned_account.local? && mentioned_account.following?(status.account) }) do |follower|
[status.id, follower.id, :home]
status.mentions.joins(:account).merge(status.account.followers_for_local_distribution).select(:id).reorder(nil).find_in_batches do |followers|
FeedInsertWorker.push_bulk(followers) do |follower|
[status.id, follower.id, :home]
end
end
end

Expand Down

0 comments on commit b1d214a

Please sign in to comment.