most_reblogged_accounts.rb 749 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,
  9. count: count,
  10. }
  11. end,
  12. }
  13. end
  14. private
  15. def most_reblogged_accounts
  16. @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'))
  17. end
  18. end