Use Mention arel/exist in report service scope build-out (#38300)

This commit is contained in:
Matt Jankowski
2026-03-20 12:03:23 -04:00
committed by GitHub
parent 806f4f1589
commit 4e276e4476

View File

@@ -88,11 +88,18 @@ 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(domain_mentions(domain))))
# Allow missing posts to not drop reports that include e.g. a deleted post
scope.where(id: Array(@status_ids)).pluck(:id)
end
def domain_mentions(domain)
Mention
.joins(:account)
.where(Account.arel_table[:domain].lower.eq domain)
.select(1).arel.exists
end
def reported_collection_ids
@target_account.collections.find(Array(@collection_ids)).pluck(:id)
end