Eager loading fixes for api/ controllers (#28848)

This commit is contained in:
Matt Jankowski 2024-01-23 06:41:54 -05:00 committed by GitHub
parent ceade78182
commit c0e8e457ab
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
13 changed files with 14 additions and 14 deletions

View File

@ -30,7 +30,7 @@ class Api::V1::Accounts::FollowerAccountsController < Api::BaseController
end end
def default_accounts def default_accounts
Account.includes(:active_relationships, :account_stat).references(:active_relationships) Account.includes(:active_relationships, :account_stat, :user).references(:active_relationships)
end end
def paginated_follows def paginated_follows

View File

@ -30,7 +30,7 @@ class Api::V1::Accounts::FollowingAccountsController < Api::BaseController
end end
def default_accounts def default_accounts
Account.includes(:passive_relationships, :account_stat).references(:passive_relationships) Account.includes(:passive_relationships, :account_stat, :user).references(:passive_relationships)
end end
def paginated_follows def paginated_follows

View File

@ -17,7 +17,7 @@ class Api::V1::BlocksController < Api::BaseController
end end
def paginated_blocks def paginated_blocks
@paginated_blocks ||= Block.eager_load(target_account: :account_stat) @paginated_blocks ||= Block.eager_load(target_account: [:account_stat, :user])
.joins(:target_account) .joins(:target_account)
.merge(Account.without_suspended) .merge(Account.without_suspended)
.where(account: current_account) .where(account: current_account)

View File

@ -27,7 +27,7 @@ class Api::V1::DirectoriesController < Api::BaseController
scope.merge!(local_account_scope) if local_accounts? scope.merge!(local_account_scope) if local_accounts?
scope.merge!(account_exclusion_scope) if current_account scope.merge!(account_exclusion_scope) if current_account
scope.merge!(account_domain_block_scope) if current_account && !local_accounts? scope.merge!(account_domain_block_scope) if current_account && !local_accounts?
end end.includes(:account_stat, user: :role)
end end
def local_accounts? def local_accounts?

View File

@ -25,7 +25,7 @@ class Api::V1::EndorsementsController < Api::BaseController
end end
def endorsed_accounts def endorsed_accounts
current_account.endorsed_accounts.includes(:account_stat).without_suspended current_account.endorsed_accounts.includes(:account_stat, :user).without_suspended
end end
def insert_pagination_headers def insert_pagination_headers

View File

@ -37,7 +37,7 @@ class Api::V1::FollowRequestsController < Api::BaseController
end end
def default_accounts def default_accounts
Account.without_suspended.includes(:follow_requests, :account_stat).references(:follow_requests) Account.without_suspended.includes(:follow_requests, :account_stat, :user).references(:follow_requests)
end end
def paginated_follow_requests def paginated_follow_requests

View File

@ -37,9 +37,9 @@ class Api::V1::Lists::AccountsController < Api::BaseController
def load_accounts def load_accounts
if unlimited? if unlimited?
@list.accounts.without_suspended.includes(:account_stat).all @list.accounts.without_suspended.includes(:account_stat, :user).all
else else
@list.accounts.without_suspended.includes(:account_stat).paginate_by_max_id(limit_param(DEFAULT_ACCOUNTS_LIMIT), params[:max_id], params[:since_id]) @list.accounts.without_suspended.includes(:account_stat, :user).paginate_by_max_id(limit_param(DEFAULT_ACCOUNTS_LIMIT), params[:max_id], params[:since_id])
end end
end end

View File

@ -17,7 +17,7 @@ class Api::V1::MutesController < Api::BaseController
end end
def paginated_mutes def paginated_mutes
@paginated_mutes ||= Mute.eager_load(:target_account) @paginated_mutes ||= Mute.eager_load(target_account: [:account_stat, :user])
.joins(:target_account) .joins(:target_account)
.merge(Account.without_suspended) .merge(Account.without_suspended)
.where(account: current_account) .where(account: current_account)

View File

@ -21,7 +21,7 @@ class Api::V1::Statuses::FavouritedByAccountsController < Api::V1::Statuses::Bas
def default_accounts def default_accounts
Account Account
.without_suspended .without_suspended
.includes(:favourites, :account_stat) .includes(:favourites, :account_stat, :user)
.references(:favourites) .references(:favourites)
.where(favourites: { status_id: @status.id }) .where(favourites: { status_id: @status.id })
end end

View File

@ -19,7 +19,7 @@ class Api::V1::Statuses::RebloggedByAccountsController < Api::V1::Statuses::Base
end end
def default_accounts def default_accounts
Account.without_suspended.includes(:statuses, :account_stat).references(:statuses) Account.without_suspended.includes(:statuses, :account_stat, :user).references(:statuses)
end end
def paginated_statuses def paginated_statuses

View File

@ -35,7 +35,7 @@ class Api::V2::FiltersController < Api::BaseController
private private
def set_filters def set_filters
@filters = current_account.custom_filters.includes(:keywords) @filters = current_account.custom_filters.includes(:keywords, :statuses)
end end
def set_filter def set_filter

View File

@ -29,7 +29,7 @@ class AccountSuggestions
# a complicated query on this end. # a complicated query on this end.
account_ids = account_ids_with_sources[offset, limit] account_ids = account_ids_with_sources[offset, limit]
accounts_map = Account.where(id: account_ids.map(&:first)).includes(:account_stat).index_by(&:id) accounts_map = Account.where(id: account_ids.map(&:first)).includes(:account_stat, :user).index_by(&:id)
account_ids.filter_map do |(account_id, source)| account_ids.filter_map do |(account_id, source)|
next unless accounts_map.key?(account_id) next unless accounts_map.key?(account_id)

View File

@ -41,7 +41,7 @@ class Report < ApplicationRecord
scope :unresolved, -> { where(action_taken_at: nil) } scope :unresolved, -> { where(action_taken_at: nil) }
scope :resolved, -> { where.not(action_taken_at: nil) } scope :resolved, -> { where.not(action_taken_at: nil) }
scope :with_accounts, -> { includes([:account, :target_account, :action_taken_by_account, :assigned_account].index_with({ user: [:invite_request, :invite] })) } scope :with_accounts, -> { includes([:account, :target_account, :action_taken_by_account, :assigned_account].index_with([:account_stat, { user: [:invite_request, :invite, :ips] }])) }
# A report is considered local if the reporter is local # A report is considered local if the reporter is local
delegate :local?, to: :account delegate :local?, to: :account