From 149648877193d410cea159029c5a3269189ab5db Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Thu, 10 Jul 2025 03:35:04 -0400 Subject: [PATCH] Add `Status#not_replying_to_account` scope for annual report classes (#35257) --- app/lib/annual_report/archetype.rb | 2 +- .../commonly_interacted_with_accounts.rb | 2 +- app/lib/annual_report/type_distribution.rb | 2 +- app/models/status.rb | 1 + spec/models/status_spec.rb | 13 +++++++++++++ 5 files changed, 17 insertions(+), 3 deletions(-) diff --git a/app/lib/annual_report/archetype.rb b/app/lib/annual_report/archetype.rb index a02dbf7db7..41973294a6 100644 --- a/app/lib/annual_report/archetype.rb +++ b/app/lib/annual_report/archetype.rb @@ -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 diff --git a/app/lib/annual_report/commonly_interacted_with_accounts.rb b/app/lib/annual_report/commonly_interacted_with_accounts.rb index c2aee44dea..219c30063a 100644 --- a/app/lib/annual_report/commonly_interacted_with_accounts.rb +++ b/app/lib/annual_report/commonly_interacted_with_accounts.rb @@ -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 diff --git a/app/lib/annual_report/type_distribution.rb b/app/lib/annual_report/type_distribution.rb index bdafe34c13..0534055c28 100644 --- a/app/lib/annual_report/type_distribution.rb +++ b/app/lib/annual_report/type_distribution.rb @@ -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, }, } diff --git a/app/models/status.rb b/app/models/status.rb index bf392317a5..e6e9450264 100644 --- a/app/models/status.rb +++ b/app/models/status.rb @@ -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) } diff --git a/spec/models/status_spec.rb b/spec/models/status_spec.rb index f3453b3b67..e0a2c39104 100644 --- a/spec/models/status_spec.rb +++ b/spec/models/status_spec.rb @@ -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')