most_reblogged_accounts.rb 666 B

12345678910111213141516171819202122
  1. # frozen_string_literal: true
  2. class AnnualReport::MostRebloggedAccounts < AnnualReport::Source
  3. SET_SIZE = 10
  4. def generate
  5. {
  6. most_reblogged_accounts: most_reblogged_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 most_reblogged_accounts
  16. 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
  17. end
  18. end