From 10c895dc849d074681e292102ec28dc3a16d2824 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Fri, 8 Nov 2024 09:21:44 -0500 Subject: [PATCH] Use existing arel scopes instead of string ordering (#32801) --- app/models/admin/status_filter.rb | 2 +- app/models/session_activation.rb | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/app/models/admin/status_filter.rb b/app/models/admin/status_filter.rb index 8d20e4f6ab..fd4d0ef59d 100644 --- a/app/models/admin/status_filter.rb +++ b/app/models/admin/status_filter.rb @@ -32,7 +32,7 @@ class Admin::StatusFilter def scope_for(key, _value) case key.to_s when 'media' - Status.joins(:media_attachments).merge(@account.media_attachments).group(:id).reorder('statuses.id desc') + Status.joins(:media_attachments).merge(@account.media_attachments).group(:id).recent else raise Mastodon::InvalidParameterError, "Unknown filter: #{key}" end diff --git a/app/models/session_activation.rb b/app/models/session_activation.rb index 31f18fd7ef..d99ecf8adb 100644 --- a/app/models/session_activation.rb +++ b/app/models/session_activation.rb @@ -30,6 +30,8 @@ class SessionActivation < ApplicationRecord DEFAULT_SCOPES = %w(read write follow).freeze + scope :latest, -> { order(id: :desc) } + class << self def active?(id) id && exists?(session_id: id) @@ -48,7 +50,7 @@ class SessionActivation < ApplicationRecord end def purge_old - order('created_at desc').offset(Rails.configuration.x.max_session_activations).destroy_all + latest.offset(Rails.configuration.x.max_session_activations).destroy_all end def exclusive(id)