Fix timeline emoji_reactions N+1 problem
This commit is contained in:
parent
7c387becb6
commit
c0ff0754a3
12 changed files with 84 additions and 16 deletions
22
app/presenters/emoji_reaction_accounts_presenter.rb
Normal file
22
app/presenters/emoji_reaction_accounts_presenter.rb
Normal file
|
@ -0,0 +1,22 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class EmojiReactionAccountsPresenter
|
||||
attr_reader :permitted_account_ids
|
||||
|
||||
def initialize(statuses, current_account_id = nil, **_options)
|
||||
@current_account_id = current_account_id
|
||||
|
||||
statuses = statuses.compact
|
||||
status_ids = statuses.flat_map { |s| [s.id, s.reblog_of_id] }.uniq.compact
|
||||
emoji_reactions = EmojiReaction.where(status_id: status_ids)
|
||||
account_ids = emoji_reactions.pluck(:account_id).uniq
|
||||
|
||||
permitted_accounts = Account.where(id: account_ids, silenced_at: nil, suspended_at: nil)
|
||||
if current_account_id.present?
|
||||
account = Account.find(current_account_id)
|
||||
permitted_accounts = permitted_accounts.where('domain IS NULL OR domain NOT IN (?)', account.excluded_from_timeline_domains) if account.present? && account.excluded_from_timeline_domains.size.positive?
|
||||
end
|
||||
|
||||
@permitted_account_ids = permitted_accounts.pluck(:id)
|
||||
end
|
||||
end
|
|
@ -4,7 +4,7 @@ class StatusRelationshipsPresenter
|
|||
PINNABLE_VISIBILITIES = %w(public public_unlisted unlisted login private).freeze
|
||||
|
||||
attr_reader :reblogs_map, :favourites_map, :mutes_map, :pins_map,
|
||||
:bookmarks_map, :filters_map, :emoji_reactions_map, :attributes_map
|
||||
:bookmarks_map, :filters_map, :emoji_reactions_map, :attributes_map, :emoji_reaction_allows_map
|
||||
|
||||
def initialize(statuses, current_account_id = nil, **options)
|
||||
@current_account_id = current_account_id
|
||||
|
@ -17,6 +17,7 @@ class StatusRelationshipsPresenter
|
|||
@pins_map = {}
|
||||
@filters_map = {}
|
||||
@emoji_reactions_map = {}
|
||||
@emoji_reaction_allows_map = nil
|
||||
else
|
||||
statuses = statuses.compact
|
||||
status_ids = statuses.flat_map { |s| [s.id, s.reblog_of_id] }.uniq.compact
|
||||
|
@ -30,6 +31,7 @@ class StatusRelationshipsPresenter
|
|||
@mutes_map = Status.mutes_map(conversation_ids, current_account_id).merge(options[:mutes_map] || {})
|
||||
@pins_map = Status.pins_map(pinnable_status_ids, current_account_id).merge(options[:pins_map] || {})
|
||||
@emoji_reactions_map = Status.emoji_reactions_map(status_ids, current_account_id).merge(options[:emoji_reactions_map] || {})
|
||||
@emoji_reaction_allows_map = Status.emoji_reaction_allows_map(status_ids, current_account_id).merge(options[:emoji_reaction_allows_map] || {})
|
||||
@attributes_map = options[:attributes_map] || {}
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue