Fix N+1 problem
This commit is contained in:
parent
1367b72fa3
commit
181cff6810
1 changed files with 19 additions and 3 deletions
|
@ -16,11 +16,10 @@ class DeliveryEmojiReactionWorker
|
|||
policy = status.account.emoji_reaction_policy
|
||||
return if policy == :block_and_hide
|
||||
|
||||
scope.includes(:user).find_each do |account|
|
||||
scope.select(:id).merge(policy_scope(status.account, policy)).includes(:user).find_each do |account|
|
||||
next if account.user.present? && (account.user.setting_stop_emoji_reaction_streaming || !account.user.setting_enable_emoji_reaction)
|
||||
next unless redis.exists?("subscribed:timeline:#{account.id}")
|
||||
next if account.excluded_from_timeline_domains.include?(reacted_account.domain)
|
||||
next if policy != :allow && !status.account.show_emoji_reaction?(account)
|
||||
next if !reacted_account.local? && account.excluded_from_timeline_domains.include?(reacted_account.domain)
|
||||
|
||||
redis.publish("timeline:#{account.id}", payload_json)
|
||||
end
|
||||
|
@ -30,4 +29,21 @@ class DeliveryEmojiReactionWorker
|
|||
rescue ActiveRecord::RecordNotFound
|
||||
true
|
||||
end
|
||||
|
||||
def policy_scope(account, policy)
|
||||
case policy
|
||||
when :block_and_hide
|
||||
Account.where(id: 0)
|
||||
when :mutuals_only
|
||||
account.mutuals.local.or(Account.where(id: account))
|
||||
when :followees_only
|
||||
account.following.local.or(Account.where(id: account))
|
||||
when :followers_only
|
||||
account.followers.local.or(Account.where(id: account))
|
||||
when :outside_only
|
||||
account.followers.local.or(Account.where(id: account.following.local)).or(Account.where(id: account))
|
||||
else
|
||||
Account.local
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue