Add AnnualReport::Source#report_statuses method for subclasses to use (#31753)
				
					
				
			This commit is contained in:
		
							parent
							
								
									559958f8c5
								
							
						
					
					
						commit
						4678473e54
					
				| @ -28,22 +28,18 @@ class AnnualReport::Archetype < AnnualReport::Source | |||||||
|   end |   end | ||||||
| 
 | 
 | ||||||
|   def polls_count |   def polls_count | ||||||
|     @polls_count ||= base_scope.where.not(poll_id: nil).count |     @polls_count ||= report_statuses.where.not(poll_id: nil).count | ||||||
|   end |   end | ||||||
| 
 | 
 | ||||||
|   def reblogs_count |   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 |   end | ||||||
| 
 | 
 | ||||||
|   def replies_count |   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 |   end | ||||||
| 
 | 
 | ||||||
|   def standalone_count |   def standalone_count | ||||||
|     @standalone_count ||= base_scope.without_replies.without_reblogs.count |     @standalone_count ||= report_statuses.without_replies.without_reblogs.count | ||||||
|   end |  | ||||||
| 
 |  | ||||||
|   def base_scope |  | ||||||
|     @account.statuses.where(id: year_as_snowflake_range) |  | ||||||
|   end |   end | ||||||
| end | end | ||||||
|  | |||||||
| @ -17,6 +17,6 @@ class AnnualReport::CommonlyInteractedWithAccounts < AnnualReport::Source | |||||||
|   private |   private | ||||||
| 
 | 
 | ||||||
|   def commonly_interacted_with_accounts |   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 | ||||||
| end | end | ||||||
|  | |||||||
| @ -17,6 +17,6 @@ class AnnualReport::MostRebloggedAccounts < AnnualReport::Source | |||||||
|   private |   private | ||||||
| 
 | 
 | ||||||
|   def most_reblogged_accounts |   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 | ||||||
| end | end | ||||||
|  | |||||||
| @ -17,6 +17,6 @@ class AnnualReport::MostUsedApps < AnnualReport::Source | |||||||
|   private |   private | ||||||
| 
 | 
 | ||||||
|   def most_used_apps |   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 | ||||||
| end | end | ||||||
|  | |||||||
| @ -17,7 +17,7 @@ class AnnualReport::Percentiles < AnnualReport::Source | |||||||
|   end |   end | ||||||
| 
 | 
 | ||||||
|   def statuses_created |   def statuses_created | ||||||
|     @statuses_created ||= @account.statuses.where(id: year_as_snowflake_range).count |     @statuses_created ||= report_statuses.count | ||||||
|   end |   end | ||||||
| 
 | 
 | ||||||
|   def total_with_fewer_followers |   def total_with_fewer_followers | ||||||
|  | |||||||
| @ -10,6 +10,13 @@ class AnnualReport::Source | |||||||
| 
 | 
 | ||||||
|   protected |   protected | ||||||
| 
 | 
 | ||||||
|  |   def report_statuses | ||||||
|  |     @account | ||||||
|  |       .statuses | ||||||
|  |       .where(id: year_as_snowflake_range) | ||||||
|  |       .reorder(nil) | ||||||
|  |   end | ||||||
|  | 
 | ||||||
|   def year_as_snowflake_range |   def year_as_snowflake_range | ||||||
|     (beginning_snowflake_id..ending_snowflake_id) |     (beginning_snowflake_id..ending_snowflake_id) | ||||||
|   end |   end | ||||||
|  | |||||||
| @ -17,7 +17,7 @@ class AnnualReport::TimeSeries < AnnualReport::Source | |||||||
|   private |   private | ||||||
| 
 | 
 | ||||||
|   def statuses_per_month |   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 |   end | ||||||
| 
 | 
 | ||||||
|   def following_per_month |   def following_per_month | ||||||
|  | |||||||
| @ -17,6 +17,6 @@ class AnnualReport::TopHashtags < AnnualReport::Source | |||||||
|   private |   private | ||||||
| 
 | 
 | ||||||
|   def top_hashtags |   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 | ||||||
| end | end | ||||||
|  | |||||||
| @ -16,6 +16,6 @@ class AnnualReport::TopStatuses < AnnualReport::Source | |||||||
|   end |   end | ||||||
| 
 | 
 | ||||||
|   def base_scope |   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 | ||||||
| end | end | ||||||
|  | |||||||
| @ -4,17 +4,11 @@ class AnnualReport::TypeDistribution < AnnualReport::Source | |||||||
|   def generate |   def generate | ||||||
|     { |     { | ||||||
|       type_distribution: { |       type_distribution: { | ||||||
|         total: base_scope.count, |         total: report_statuses.count, | ||||||
|         reblogs: base_scope.where.not(reblog_of_id: nil).count, |         reblogs: report_statuses.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, |         replies: report_statuses.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, |         standalone: report_statuses.without_replies.without_reblogs.count, | ||||||
|       }, |       }, | ||||||
|     } |     } | ||||||
|   end |   end | ||||||
| 
 |  | ||||||
|   private |  | ||||||
| 
 |  | ||||||
|   def base_scope |  | ||||||
|     @account.statuses.where(id: year_as_snowflake_range) |  | ||||||
|   end |  | ||||||
| end | end | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user