Use group/count approach in annual report classes (#32914)
This commit is contained in:
		@@ -17,6 +17,6 @@ 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('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(count_all: :desc).limit(SET_SIZE).count
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
 
 | 
			
		||||
@@ -17,6 +17,6 @@ class AnnualReport::MostRebloggedAccounts < AnnualReport::Source
 | 
			
		||||
  private
 | 
			
		||||
 | 
			
		||||
  def most_reblogged_accounts
 | 
			
		||||
    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'))
 | 
			
		||||
    report_statuses.where.not(reblog_of_id: nil).joins(reblog: :account).group('accounts.id').having('count(*) > 1').order(count_all: :desc).limit(SET_SIZE).count
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
 
 | 
			
		||||
@@ -17,6 +17,6 @@ class AnnualReport::MostUsedApps < AnnualReport::Source
 | 
			
		||||
  private
 | 
			
		||||
 | 
			
		||||
  def most_used_apps
 | 
			
		||||
    report_statuses.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(count_all: :desc).limit(SET_SIZE).count
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
 
 | 
			
		||||
@@ -17,6 +17,12 @@ class AnnualReport::TopHashtags < AnnualReport::Source
 | 
			
		||||
  private
 | 
			
		||||
 | 
			
		||||
  def top_hashtags
 | 
			
		||||
    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'))
 | 
			
		||||
    Tag.joins(:statuses).where(statuses: { id: report_statuses.select(:id) }).group(coalesced_tag_names).having('count(*) > 1').order(count_all: :desc).limit(SET_SIZE).count
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def coalesced_tag_names
 | 
			
		||||
    Arel.sql(<<~SQL.squish)
 | 
			
		||||
      COALESCE(tags.display_name, tags.name)
 | 
			
		||||
    SQL
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user