Add Account migration scopes

This commit is contained in:
Matt Jankowski 2024-01-25 12:13:55 -05:00
parent d9eee9bf9a
commit 44cb03d4f9
2 changed files with 5 additions and 3 deletions

View File

@ -119,8 +119,10 @@ class Account < ApplicationRecord
scope :silenced, -> { where.not(silenced_at: nil) }
scope :suspended, -> { where.not(suspended_at: nil) }
scope :sensitized, -> { where.not(sensitized_at: nil) }
scope :migrated, -> { where.not(moved_to_account_id: nil) }
scope :without_suspended, -> { where(suspended_at: nil) }
scope :without_silenced, -> { where(silenced_at: nil) }
scope :without_migrated, -> { where(moved_to_account_id: nil) }
scope :without_instance_actor, -> { where.not(id: INSTANCE_ACTOR_ID) }
scope :recent, -> { reorder(id: :desc) }
scope :bots, -> { where(actor_type: %w(Application Service)) }
@ -131,7 +133,7 @@ class Account < ApplicationRecord
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 :searchable, -> { without_unapproved.without_suspended.without_migrated }
scope :discoverable, -> { searchable.without_silenced.where(discoverable: true).joins(:account_stat) }
scope :by_recent_status, -> { includes(:account_stat).merge(AccountStat.by_recent_status).references(:account_stat) }
scope :by_recent_activity, -> { left_joins(:user, :account_stat).order(coalesced_activity_timestamps.desc).order(id: :desc) }

View File

@ -92,9 +92,9 @@ class RelationshipFilter
def status_scope(value)
case value
when 'moved'
Account.where.not(moved_to_account_id: nil)
Account.migrated
when 'primary'
Account.where(moved_to_account_id: nil)
Account.without_migrated
else
raise Mastodon::InvalidParameterError, "Unknown status: #{value}"
end