Use arel order in account interactions

This commit is contained in:
Matt Jankowski 2024-07-30 16:56:18 -04:00
parent fd74536f13
commit 31537ab5ed
3 changed files with 10 additions and 6 deletions

View file

@ -21,6 +21,8 @@ class Block < ApplicationRecord
validates :account_id, uniqueness: { scope: :target_account_id }
scope :recent, -> { reorder(id: :desc) }
def local?
false # Force uri_for to use uri attribute
end

View file

@ -80,8 +80,8 @@ module Account::Interactions
has_many :passive_relationships, foreign_key: 'target_account_id', inverse_of: :target_account
end
has_many :following, -> { order('follows.id desc') }, through: :active_relationships, source: :target_account
has_many :followers, -> { order('follows.id desc') }, through: :passive_relationships, source: :account
has_many :following, -> { Follow.recent }, through: :active_relationships, source: :target_account
has_many :followers, -> { Follow.recent }, through: :passive_relationships, source: :account
with_options class_name: 'SeveredRelationship', dependent: :destroy do
has_many :severed_relationships, foreign_key: 'local_account_id', inverse_of: :local_account
@ -96,16 +96,16 @@ module Account::Interactions
has_many :block_relationships, foreign_key: 'account_id', inverse_of: :account
has_many :blocked_by_relationships, foreign_key: :target_account_id, inverse_of: :target_account
end
has_many :blocking, -> { order('blocks.id desc') }, through: :block_relationships, source: :target_account
has_many :blocked_by, -> { order('blocks.id desc') }, through: :blocked_by_relationships, source: :account
has_many :blocking, -> { Block.recent }, through: :block_relationships, source: :target_account
has_many :blocked_by, -> { Block.recent }, through: :blocked_by_relationships, source: :account
# Mute relationships
with_options class_name: 'Mute', dependent: :destroy do
has_many :mute_relationships, foreign_key: 'account_id', inverse_of: :account
has_many :muted_by_relationships, foreign_key: :target_account_id, inverse_of: :target_account
end
has_many :muting, -> { order('mutes.id desc') }, through: :mute_relationships, source: :target_account
has_many :muted_by, -> { order('mutes.id desc') }, through: :muted_by_relationships, source: :account
has_many :muting, -> { Mute.recent }, through: :mute_relationships, source: :target_account
has_many :muted_by, -> { Mute.recent }, through: :muted_by_relationships, source: :account
has_many :conversation_mutes, dependent: :destroy
has_many :domain_blocks, class_name: 'AccountDomainBlock', dependent: :destroy
has_many :announcement_mutes, dependent: :destroy

View file

@ -23,6 +23,8 @@ class Mute < ApplicationRecord
validates :account_id, uniqueness: { scope: :target_account_id }
scope :recent, -> { reorder(id: :desc) }
after_commit :invalidate_blocking_cache
after_commit :invalidate_follow_recommendations_cache