1
0
Fork 0
mirror of https://github.com/mastodon/mastodon.git synced 2024-08-20 21:08:15 -07:00

Make use of existing Account.with_domain scope for ReportService#reported_status_ids

This commit is contained in:
Matt Jankowski 2024-07-31 11:32:14 -04:00
parent 584b1524dd
commit e1008e9eb5

View file

@ -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