From e1008e9eb510b587b1e7b39137a130ce633cbc24 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Wed, 31 Jul 2024 11:32:14 -0400 Subject: [PATCH] Make use of existing `Account.with_domain` scope for `ReportService#reported_status_ids` --- app/services/report_service.rb | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/app/services/report_service.rb b/app/services/report_service.rb index c95e216c790..0aeda15dfb4 100644 --- a/app/services/report_service.rb +++ b/app/services/report_service.rb @@ -86,7 +86,7 @@ class ReportService < BaseService has_followers = @target_account.followers.with_domain(domain).exists? visibility = has_followers ? %i(public unlisted private) : %i(public unlisted) scope = @target_account.statuses.with_discarded - scope.merge!(scope.where(visibility: visibility).or(scope.where('EXISTS (SELECT 1 FROM mentions m JOIN accounts a ON m.account_id = a.id WHERE lower(a.domain) = ?)', domain))) + scope.merge!(scope.where(visibility: visibility).or(scope.where(exists_mention_for_domain_accounts(domain)))) # Allow missing posts to not drop reports that include e.g. a deleted post scope.where(id: Array(@status_ids)).pluck(:id) end @@ -98,4 +98,13 @@ class ReportService < BaseService def some_local_account @some_local_account ||= Account.representative end + + def exists_mention_for_domain_accounts(domain) + Mention + .joins(:account) + .merge(Account.with_domain(domain)) + .select(1) + .arel + .exists + end end