From e6969cf4e434abb7a03a1f1300e97f031b23a042 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Mon, 9 Sep 2024 04:33:51 -0400 Subject: [PATCH] Add method for media-referencing status in `AccountStatusCleanupPolicy` (#31798) --- app/models/account_statuses_cleanup_policy.rb | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/app/models/account_statuses_cleanup_policy.rb b/app/models/account_statuses_cleanup_policy.rb index e2c035284..6e998e2dc 100644 --- a/app/models/account_statuses_cleanup_policy.rb +++ b/app/models/account_statuses_cleanup_policy.rb @@ -157,7 +157,7 @@ class AccountStatusesCleanupPolicy < ApplicationRecord end def without_media_scope - Status.where('NOT EXISTS (SELECT 1 FROM media_attachments media WHERE media.status_id = statuses.id)') + Status.where.not(status_media_reference_exists) end def without_poll_scope @@ -175,6 +175,14 @@ class AccountStatusesCleanupPolicy < ApplicationRecord Status.where(account_id: account_id) end + def status_media_reference_exists + MediaAttachment + .where(MediaAttachment.arel_table[:status_id].eq Status.arel_table[:id]) + .select(1) + .arel + .exists + end + def self_status_reference_exists(model) model .where(model.arel_table[:account_id].eq Status.arel_table[:account_id])