Add Status#not_replying_to_account scope for annual report classes (#35257)

This commit is contained in:
Matt Jankowski 2025-07-10 03:35:04 -04:00 committed by GitHub
parent dd3d958e75
commit 1496488771
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 17 additions and 3 deletions

View File

@ -36,7 +36,7 @@ class AnnualReport::Archetype < AnnualReport::Source
end
def replies_count
@replies_count ||= report_statuses.where.not(in_reply_to_id: nil).where.not(in_reply_to_account_id: @account.id).count
@replies_count ||= report_statuses.where.not(in_reply_to_id: nil).not_replying_to_account(@account).count
end
def standalone_count

View File

@ -18,7 +18,7 @@ class AnnualReport::CommonlyInteractedWithAccounts < AnnualReport::Source
private
def commonly_interacted_with_accounts
report_statuses.where.not(in_reply_to_account_id: @account.id).group(:in_reply_to_account_id).having(minimum_interaction_count).order(count_all: :desc).limit(SET_SIZE).count
report_statuses.not_replying_to_account(@account).group(:in_reply_to_account_id).having(minimum_interaction_count).order(count_all: :desc).limit(SET_SIZE).count
end
def minimum_interaction_count

View File

@ -6,7 +6,7 @@ class AnnualReport::TypeDistribution < AnnualReport::Source
type_distribution: {
total: report_statuses.count,
reblogs: report_statuses.only_reblogs.count,
replies: report_statuses.where.not(in_reply_to_id: nil).where.not(in_reply_to_account_id: @account.id).count,
replies: report_statuses.where.not(in_reply_to_id: nil).not_replying_to_account(@account).count,
standalone: report_statuses.without_replies.without_reblogs.count,
},
}

View File

@ -124,6 +124,7 @@ class Status < ApplicationRecord
scope :only_polls, -> { where.not(poll_id: nil) }
scope :without_polls, -> { where(poll_id: nil) }
scope :reply_to_account, -> { where(arel_table[:in_reply_to_account_id].eq arel_table[:account_id]) }
scope :not_replying_to_account, ->(account) { where.not(in_reply_to_account: account) }
scope :without_reblogs, -> { where(statuses: { reblog_of_id: nil }) }
scope :tagged_with, ->(tag_ids) { joins(:statuses_tags).where(statuses_tags: { tag_id: tag_ids }) }
scope :not_excluded_by_account, ->(account) { where.not(account_id: account.excluded_from_timeline_account_ids) }

View File

@ -191,6 +191,19 @@ RSpec.describe Status do
end
end
describe '.not_replying_to_account' do
let(:account) { Fabricate :account }
let!(:status_from_account) { Fabricate :status, account: account }
let!(:reply_to_account_status) { Fabricate :status, thread: status_from_account }
let!(:reply_to_other) { Fabricate :status, thread: Fabricate(:status) }
it 'returns records not in reply to provided account' do
expect(described_class.not_replying_to_account(account))
.to not_include(reply_to_account_status)
.and include(reply_to_other)
end
end
describe '#untrusted_favourites_count' do
before do
alice.update(domain: 'example.com')