From bd6bb4debe601aeea2b31143b1b1eb31777e0d45 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Tue, 30 Jul 2024 16:56:18 -0400 Subject: [PATCH] Use arel order in account interactions --- app/models/block.rb | 2 ++ app/models/concerns/account/interactions.rb | 12 ++++++------ app/models/mute.rb | 2 ++ 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/app/models/block.rb b/app/models/block.rb index 5476542a5ab..6b4be8820e7 100644 --- a/app/models/block.rb +++ b/app/models/block.rb @@ -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 diff --git a/app/models/concerns/account/interactions.rb b/app/models/concerns/account/interactions.rb index 536afba17fa..d7a327ed55a 100644 --- a/app/models/concerns/account/interactions.rb +++ b/app/models/concerns/account/interactions.rb @@ -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 diff --git a/app/models/mute.rb b/app/models/mute.rb index 1d18b30eea9..3010c7e6ec1 100644 --- a/app/models/mute.rb +++ b/app/models/mute.rb @@ -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