instance_accounts_dimension.rb 844 B

1234567891011121314151617181920212223242526272829303132333435
  1. # frozen_string_literal: true
  2. class Admin::Metrics::Dimension::InstanceAccountsDimension < Admin::Metrics::Dimension::BaseDimension
  3. include LanguagesHelper
  4. def self.with_params?
  5. true
  6. end
  7. def key
  8. 'instance_accounts'
  9. end
  10. protected
  11. def perform_query
  12. sql = <<-SQL.squish
  13. SELECT accounts.username, count(follows.*) AS value
  14. FROM accounts
  15. LEFT JOIN follows ON follows.target_account_id = accounts.id
  16. WHERE accounts.domain = $1
  17. GROUP BY accounts.id, follows.target_account_id
  18. ORDER BY value DESC
  19. LIMIT $2
  20. SQL
  21. rows = ActiveRecord::Base.connection.select_all(sql, nil, [[nil, params[:domain]], [nil, @limit]])
  22. rows.map { |row| { key: row['username'], human_key: row['username'], value: row['value'].to_s } }
  23. end
  24. def params
  25. @params.permit(:domain)
  26. end
  27. end