Use existing arel scopes instead of string ordering (#32801)

pull/2894/head
Matt Jankowski 2024-11-08 09:21:44 -05:00 committed by GitHub
parent bde0f1239a
commit 10c895dc84
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 4 additions and 2 deletions

View File

@ -32,7 +32,7 @@ class Admin::StatusFilter
def scope_for(key, _value) def scope_for(key, _value)
case key.to_s case key.to_s
when 'media' 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 else
raise Mastodon::InvalidParameterError, "Unknown filter: #{key}" raise Mastodon::InvalidParameterError, "Unknown filter: #{key}"
end end

View File

@ -30,6 +30,8 @@ class SessionActivation < ApplicationRecord
DEFAULT_SCOPES = %w(read write follow).freeze DEFAULT_SCOPES = %w(read write follow).freeze
scope :latest, -> { order(id: :desc) }
class << self class << self
def active?(id) def active?(id)
id && exists?(session_id: id) id && exists?(session_id: id)
@ -48,7 +50,7 @@ class SessionActivation < ApplicationRecord
end end
def purge_old 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 end
def exclusive(id) def exclusive(id)