commonly_interacted_with_accounts.rb 757 B

12345678910111213141516171819202122
  1. # frozen_string_literal: true
  2. class AnnualReport::CommonlyInteractedWithAccounts < AnnualReport::Source
  3. SET_SIZE = 40
  4. def generate
  5. {
  6. commonly_interacted_with_accounts: commonly_interacted_with_accounts.map do |(account_id, count)|
  7. {
  8. account_id: account_id.to_s,
  9. count: count,
  10. }
  11. end,
  12. }
  13. end
  14. private
  15. def commonly_interacted_with_accounts
  16. 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
  17. end
  18. end