Add Account.auditable scope, fix N+1 in admin/action_logs#index (#28812)
This commit is contained in:
@@ -6,7 +6,7 @@ module Admin
|
||||
|
||||
def index
|
||||
authorize :audit_log, :index?
|
||||
@auditable_accounts = Account.where(id: Admin::ActionLog.select('distinct account_id')).select(:id, :username)
|
||||
@auditable_accounts = Account.auditable.select(:id, :username)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
@@ -126,6 +126,7 @@ class Account < ApplicationRecord
|
||||
scope :matches_username, ->(value) { where('lower((username)::text) LIKE lower(?)', "#{value}%") }
|
||||
scope :matches_display_name, ->(value) { where(arel_table[:display_name].matches("#{value}%")) }
|
||||
scope :without_unapproved, -> { left_outer_joins(:user).merge(User.approved.confirmed).or(remote) }
|
||||
scope :auditable, -> { where(id: Admin::ActionLog.select(:account_id).distinct) }
|
||||
scope :searchable, -> { without_unapproved.without_suspended.where(moved_to_account_id: nil) }
|
||||
scope :discoverable, -> { searchable.without_silenced.where(discoverable: true).joins(:account_stat) }
|
||||
scope :by_recent_status, -> { includes(:account_stat).merge(AccountStat.order('last_status_at DESC NULLS LAST')).references(:account_stat) }
|
||||
|
||||
@@ -72,7 +72,7 @@ class Admin::ActionLogFilter
|
||||
end
|
||||
|
||||
def results
|
||||
scope = latest_action_logs.includes(:target)
|
||||
scope = latest_action_logs.includes(:target, :account)
|
||||
|
||||
params.each do |key, value|
|
||||
next if key.to_s == 'page'
|
||||
|
||||
Reference in New Issue
Block a user