Skip to content

Commit

Permalink
Remove default_scope from MediaAttachment class (mastodon#28043)
Browse files Browse the repository at this point in the history
  • Loading branch information
mjankowski authored Nov 30, 2023
1 parent 02a9821 commit bb0efe1
Show file tree
Hide file tree
Showing 11 changed files with 14 additions and 15 deletions.
2 changes: 1 addition & 1 deletion app/controllers/accounts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def default_statuses
end

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

def no_replies_scope
Expand Down
2 changes: 1 addition & 1 deletion app/lib/account_statuses_filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def filtered_reblogs_scope
end

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

def no_replies_scope
Expand Down
4 changes: 2 additions & 2 deletions app/lib/vacuum/media_attachments_vacuum.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ def vacuum_orphaned_records!
end

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

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

def retention_period?
Expand Down
2 changes: 1 addition & 1 deletion app/models/admin/status_filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def results
def scope_for(key, _value)
case key.to_s
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
raise Mastodon::InvalidParameterError, "Unknown filter: #{key}"
end
Expand Down
7 changes: 3 additions & 4 deletions app/models/media_attachment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -205,12 +205,11 @@ class MediaAttachment < ApplicationRecord
validates :thumbnail, absence: true, if: -> { local? && !audio_or_video? }

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 :cached, -> { remote.where.not(file_file_name: nil) }
scope :local, -> { where(remote_url: '') }
scope :ordered, -> { order(id: :asc) }
scope :remote, -> { where.not(remote_url: '') }
scope :cached, -> { remote.where.not(file_file_name: nil) }

default_scope { order(id: :asc) }
scope :unattached, -> { where(status_id: nil, scheduled_status_id: nil) }

attr_accessor :skip_download

Expand Down
2 changes: 1 addition & 1 deletion app/services/backup_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def build_archive!
end

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|
path = m.file&.path
next unless path
Expand Down
2 changes: 1 addition & 1 deletion app/services/clear_domain_media_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def blocked_domain_accounts
end

def media_from_blocked_domain
MediaAttachment.joins(:account).merge(blocked_domain_accounts).reorder(nil)
MediaAttachment.joins(:account).merge(blocked_domain_accounts)
end

def emojis_from_blocked_domains
Expand Down
2 changes: 1 addition & 1 deletion app/services/delete_account_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ def purge_mentions!
end

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)

media_attachment.destroy
Expand Down
2 changes: 1 addition & 1 deletion app/services/suspend_account_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def unmerge_from_list_timelines!
def privatize_media_attachments!
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 = media_attachment.public_send(attachment_name)
styles = MediaAttachment::DEFAULT_STYLES | attachment.styles.keys
Expand Down
2 changes: 1 addition & 1 deletion app/services/unsuspend_account_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def merge_into_list_timelines!
def publish_media_attachments!
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 = media_attachment.public_send(attachment_name)
styles = MediaAttachment::DEFAULT_STYLES | attachment.styles.keys
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ def poll_option_json(name, votes)
end

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.remote_url).to eq 'https://example.com/foo.png'
Expand Down

0 comments on commit bb0efe1

Please sign in to comment.