instance_accounts_dimension.rb 926 B

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