diff --git a/app/lib/annual_report/time_series.rb b/app/lib/annual_report/time_series.rb index 3f9f0d52e88..fc2c5e2ce46 100644 --- a/app/lib/annual_report/time_series.rb +++ b/app/lib/annual_report/time_series.rb @@ -3,29 +3,24 @@ class AnnualReport::TimeSeries < AnnualReport::Source def generate { - time_series: (1..12).map do |month| - { - month: month, - statuses: statuses_per_month[month] || 0, - following: following_per_month[month] || 0, - followers: followers_per_month[month] || 0, - } - end, + time_series: [ + { + month: 12, + statuses: statuses_this_year, + followers: followers_this_year, + }, + ], } end private - def statuses_per_month - @statuses_per_month ||= report_statuses.group(:period).pluck(date_part_month.as('period'), Arel.star.count).to_h + def statuses_this_year + @statuses_this_year ||= report_statuses.count end - def following_per_month - @following_per_month ||= annual_relationships_by_month(@account.active_relationships) - end - - def followers_per_month - @followers_per_month ||= annual_relationships_by_month(@account.passive_relationships) + def followers_this_year + @followers_this_year ||= @account.passive_relationships.where(created_in_year, @year).count end def date_part_month @@ -34,14 +29,6 @@ class AnnualReport::TimeSeries < AnnualReport::Source SQL end - def annual_relationships_by_month(relationships) - relationships - .where(created_in_year, @year) - .group(:period) - .pluck(date_part_month.as('period'), Arel.star.count) - .to_h - end - def created_in_year Arel.sql(<<~SQL.squish) DATE_PART('year', created_at) = ? diff --git a/spec/lib/annual_report/time_series_spec.rb b/spec/lib/annual_report/time_series_spec.rb index 219d6c08347..046ac5b2025 100644 --- a/spec/lib/annual_report/time_series_spec.rb +++ b/spec/lib/annual_report/time_series_spec.rb @@ -13,7 +13,7 @@ RSpec.describe AnnualReport::TimeSeries do expect(subject.generate) .to include( time_series: match( - include(followers: 0, following: 0, month: 1, statuses: 0) + include(followers: 0, month: 12, statuses: 0) ) ) end @@ -37,7 +37,7 @@ RSpec.describe AnnualReport::TimeSeries do expect(subject.generate) .to include( time_series: match( - include(followers: 1, following: 1, month: 1, statuses: 1) + include(followers: 1, month: 12, statuses: 1) ) ) end