Remove `default_scope` from `MediaAttachment` class (#28043)

main
Matt Jankowski 2023-11-30 08:30:35 -05:00 committed by GitHub
parent 02a98210e8
commit bb0efe16e6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 15 additions and 16 deletions

View File

@ -50,7 +50,7 @@ class AccountsController < ApplicationController
end end
def only_media_scope def only_media_scope
Status.joins(:media_attachments).merge(@account.media_attachments.reorder(nil)).group(:id) Status.joins(:media_attachments).merge(@account.media_attachments).group(:id)
end end
def no_replies_scope def no_replies_scope

View File

@ -70,7 +70,7 @@ class AccountStatusesFilter
end end
def only_media_scope def only_media_scope
Status.joins(:media_attachments).merge(account.media_attachments.reorder(nil)).group(Status.arel_table[:id]) Status.joins(:media_attachments).merge(account.media_attachments).group(Status.arel_table[:id])
end end
def no_replies_scope def no_replies_scope

View File

@ -27,11 +27,11 @@ class Vacuum::MediaAttachmentsVacuum
end end
def media_attachments_past_retention_period def media_attachments_past_retention_period
MediaAttachment.unscoped.remote.cached.where(MediaAttachment.arel_table[:created_at].lt(@retention_period.ago)).where(MediaAttachment.arel_table[:updated_at].lt(@retention_period.ago)) MediaAttachment.remote.cached.where(MediaAttachment.arel_table[:created_at].lt(@retention_period.ago)).where(MediaAttachment.arel_table[:updated_at].lt(@retention_period.ago))
end end
def orphaned_media_attachments def orphaned_media_attachments
MediaAttachment.unscoped.unattached.where(MediaAttachment.arel_table[:created_at].lt(TTL.ago)) MediaAttachment.unattached.where(MediaAttachment.arel_table[:created_at].lt(TTL.ago))
end end
def retention_period? def retention_period?

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.reorder(nil)).group(:id).reorder('statuses.id desc') Status.joins(:media_attachments).merge(@account.media_attachments).group(:id).reorder('statuses.id desc')
else else
raise Mastodon::InvalidParameterError, "Unknown filter: #{key}" raise Mastodon::InvalidParameterError, "Unknown filter: #{key}"
end end

View File

@ -205,12 +205,11 @@ class MediaAttachment < ApplicationRecord
validates :thumbnail, absence: true, if: -> { local? && !audio_or_video? } validates :thumbnail, absence: true, if: -> { local? && !audio_or_video? }
scope :attached, -> { where.not(status_id: nil).or(where.not(scheduled_status_id: nil)) } scope :attached, -> { where.not(status_id: nil).or(where.not(scheduled_status_id: nil)) }
scope :unattached, -> { where(status_id: nil, scheduled_status_id: nil) }
scope :local, -> { where(remote_url: '') }
scope :remote, -> { where.not(remote_url: '') }
scope :cached, -> { remote.where.not(file_file_name: nil) } scope :cached, -> { remote.where.not(file_file_name: nil) }
scope :local, -> { where(remote_url: '') }
default_scope { order(id: :asc) } scope :ordered, -> { order(id: :asc) }
scope :remote, -> { where.not(remote_url: '') }
scope :unattached, -> { where(status_id: nil, scheduled_status_id: nil) }
attr_accessor :skip_download attr_accessor :skip_download

View File

@ -72,7 +72,7 @@ class BackupService < BaseService
end end
def dump_media_attachments!(zipfile) def dump_media_attachments!(zipfile)
MediaAttachment.attached.where(account: account).reorder(nil).find_in_batches do |media_attachments| MediaAttachment.attached.where(account: account).find_in_batches do |media_attachments|
media_attachments.each do |m| media_attachments.each do |m|
path = m.file&.path path = m.file&.path
next unless path next unless path

View File

@ -43,7 +43,7 @@ class ClearDomainMediaService < BaseService
end end
def media_from_blocked_domain def media_from_blocked_domain
MediaAttachment.joins(:account).merge(blocked_domain_accounts).reorder(nil) MediaAttachment.joins(:account).merge(blocked_domain_accounts)
end end
def emojis_from_blocked_domains def emojis_from_blocked_domains

View File

@ -165,7 +165,7 @@ class DeleteAccountService < BaseService
end end
def purge_media_attachments! def purge_media_attachments!
@account.media_attachments.reorder(nil).find_each do |media_attachment| @account.media_attachments.find_each do |media_attachment|
next if keep_account_record? && reported_status_ids.include?(media_attachment.status_id) next if keep_account_record? && reported_status_ids.include?(media_attachment.status_id)
media_attachment.destroy media_attachment.destroy

View File

@ -65,7 +65,7 @@ class SuspendAccountService < BaseService
def privatize_media_attachments! def privatize_media_attachments!
attachment_names = MediaAttachment.attachment_definitions.keys attachment_names = MediaAttachment.attachment_definitions.keys
@account.media_attachments.reorder(nil).find_each do |media_attachment| @account.media_attachments.find_each do |media_attachment|
attachment_names.each do |attachment_name| attachment_names.each do |attachment_name|
attachment = media_attachment.public_send(attachment_name) attachment = media_attachment.public_send(attachment_name)
styles = MediaAttachment::DEFAULT_STYLES | attachment.styles.keys styles = MediaAttachment::DEFAULT_STYLES | attachment.styles.keys

View File

@ -61,7 +61,7 @@ class UnsuspendAccountService < BaseService
def publish_media_attachments! def publish_media_attachments!
attachment_names = MediaAttachment.attachment_definitions.keys attachment_names = MediaAttachment.attachment_definitions.keys
@account.media_attachments.reorder(nil).find_each do |media_attachment| @account.media_attachments.find_each do |media_attachment|
attachment_names.each do |attachment_name| attachment_names.each do |attachment_name|
attachment = media_attachment.public_send(attachment_name) attachment = media_attachment.public_send(attachment_name)
styles = MediaAttachment::DEFAULT_STYLES | attachment.styles.keys styles = MediaAttachment::DEFAULT_STYLES | attachment.styles.keys

View File

@ -384,7 +384,7 @@ RSpec.describe ActivityPub::ProcessStatusUpdateService, type: :service do
end end
it 'updates the existing media attachment in-place' do it 'updates the existing media attachment in-place' do
media_attachment = status.media_attachments.reload.first media_attachment = status.media_attachments.ordered.reload.first
expect(media_attachment).to_not be_nil expect(media_attachment).to_not be_nil
expect(media_attachment.remote_url).to eq 'https://example.com/foo.png' expect(media_attachment.remote_url).to eq 'https://example.com/foo.png'