Add AnnualReport::Source#report_statuses method for subclasses to use (#31753)

This commit is contained in:
Matt Jankowski 2024-09-04 15:50:33 -04:00 committed by GitHub
parent 559958f8c5
commit 4678473e54
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 22 additions and 25 deletions

View file

@ -28,22 +28,18 @@ class AnnualReport::Archetype < AnnualReport::Source
end
def polls_count
@polls_count ||= base_scope.where.not(poll_id: nil).count
@polls_count ||= report_statuses.where.not(poll_id: nil).count
end
def reblogs_count
@reblogs_count ||= base_scope.where.not(reblog_of_id: nil).count
@reblogs_count ||= report_statuses.where.not(reblog_of_id: nil).count
end
def replies_count
@replies_count ||= base_scope.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).where.not(in_reply_to_account_id: @account.id).count
end
def standalone_count
@standalone_count ||= base_scope.without_replies.without_reblogs.count
end
def base_scope
@account.statuses.where(id: year_as_snowflake_range)
@standalone_count ||= report_statuses.without_replies.without_reblogs.count
end
end

View file

@ -17,6 +17,6 @@ class AnnualReport::CommonlyInteractedWithAccounts < AnnualReport::Source
private
def commonly_interacted_with_accounts
@account.statuses.reorder(nil).where(id: year_as_snowflake_range).where.not(in_reply_to_account_id: @account.id).group(:in_reply_to_account_id).having('count(*) > 1').order(total: :desc).limit(SET_SIZE).pluck(Arel.sql('in_reply_to_account_id, count(*) AS total'))
report_statuses.where.not(in_reply_to_account_id: @account.id).group(:in_reply_to_account_id).having('count(*) > 1').order(total: :desc).limit(SET_SIZE).pluck(Arel.sql('in_reply_to_account_id, count(*) AS total'))
end
end

View file

@ -17,6 +17,6 @@ class AnnualReport::MostRebloggedAccounts < AnnualReport::Source
private
def most_reblogged_accounts
@account.statuses.reorder(nil).where(id: year_as_snowflake_range).where.not(reblog_of_id: nil).joins(reblog: :account).group('accounts.id').having('count(*) > 1').order(total: :desc).limit(SET_SIZE).pluck(Arel.sql('accounts.id, count(*) as total'))
report_statuses.where.not(reblog_of_id: nil).joins(reblog: :account).group('accounts.id').having('count(*) > 1').order(total: :desc).limit(SET_SIZE).pluck(Arel.sql('accounts.id, count(*) as total'))
end
end

View file

@ -17,6 +17,6 @@ class AnnualReport::MostUsedApps < AnnualReport::Source
private
def most_used_apps
@account.statuses.reorder(nil).where(id: year_as_snowflake_range).joins(:application).group('oauth_applications.name').order(total: :desc).limit(SET_SIZE).pluck(Arel.sql('oauth_applications.name, count(*) as total'))
report_statuses.joins(:application).group('oauth_applications.name').order(total: :desc).limit(SET_SIZE).pluck(Arel.sql('oauth_applications.name, count(*) as total'))
end
end

View file

@ -17,7 +17,7 @@ class AnnualReport::Percentiles < AnnualReport::Source
end
def statuses_created
@statuses_created ||= @account.statuses.where(id: year_as_snowflake_range).count
@statuses_created ||= report_statuses.count
end
def total_with_fewer_followers

View file

@ -10,6 +10,13 @@ class AnnualReport::Source
protected
def report_statuses
@account
.statuses
.where(id: year_as_snowflake_range)
.reorder(nil)
end
def year_as_snowflake_range
(beginning_snowflake_id..ending_snowflake_id)
end

View file

@ -17,7 +17,7 @@ class AnnualReport::TimeSeries < AnnualReport::Source
private
def statuses_per_month
@statuses_per_month ||= @account.statuses.reorder(nil).where(id: year_as_snowflake_range).group(:period).pluck(Arel.sql("date_part('month', created_at)::int AS period, count(*)")).to_h
@statuses_per_month ||= report_statuses.group(:period).pluck(Arel.sql("date_part('month', created_at)::int AS period, count(*)")).to_h
end
def following_per_month

View file

@ -17,6 +17,6 @@ class AnnualReport::TopHashtags < AnnualReport::Source
private
def top_hashtags
Tag.joins(:statuses).where(statuses: { id: @account.statuses.where(id: year_as_snowflake_range).reorder(nil).select(:id) }).group(:id).having('count(*) > 1').order(total: :desc).limit(SET_SIZE).pluck(Arel.sql('COALESCE(tags.display_name, tags.name), count(*) AS total'))
Tag.joins(:statuses).where(statuses: { id: report_statuses.select(:id) }).group(:id).having('count(*) > 1').order(total: :desc).limit(SET_SIZE).pluck(Arel.sql('COALESCE(tags.display_name, tags.name), count(*) AS total'))
end
end

View file

@ -16,6 +16,6 @@ class AnnualReport::TopStatuses < AnnualReport::Source
end
def base_scope
@account.statuses.public_visibility.joins(:status_stat).where(id: year_as_snowflake_range).reorder(nil)
report_statuses.public_visibility.joins(:status_stat)
end
end

View file

@ -4,17 +4,11 @@ class AnnualReport::TypeDistribution < AnnualReport::Source
def generate
{
type_distribution: {
total: base_scope.count,
reblogs: base_scope.where.not(reblog_of_id: nil).count,
replies: base_scope.where.not(in_reply_to_id: nil).where.not(in_reply_to_account_id: @account.id).count,
standalone: base_scope.without_replies.without_reblogs.count,
total: report_statuses.count,
reblogs: report_statuses.where.not(reblog_of_id: nil).count,
replies: report_statuses.where.not(in_reply_to_id: nil).where.not(in_reply_to_account_id: @account.id).count,
standalone: report_statuses.without_replies.without_reblogs.count,
},
}
end
private
def base_scope
@account.statuses.where(id: year_as_snowflake_range)
end
end