servers_dimension.rb 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. # frozen_string_literal: true
  2. class Admin::Metrics::Dimension::ServersDimension < Admin::Metrics::Dimension::BaseDimension
  3. include Admin::Metrics::Dimension::QueryHelper
  4. def key
  5. 'servers'
  6. end
  7. protected
  8. def perform_query
  9. dimension_data_rows.map { |row| { key: row['domain'] || Rails.configuration.x.local_domain, human_key: row['domain'] || Rails.configuration.x.local_domain, value: row['value'].to_s } }
  10. end
  11. def sql_array
  12. [sql_query_string, { earliest_status_id: earliest_status_id, latest_status_id: latest_status_id, limit: @limit }]
  13. end
  14. def sql_query_string
  15. <<~SQL.squish
  16. SELECT accounts.domain, count(*) AS value
  17. FROM statuses
  18. INNER JOIN accounts ON accounts.id = statuses.account_id
  19. WHERE statuses.id BETWEEN :earliest_status_id AND :latest_status_id
  20. GROUP BY accounts.domain
  21. ORDER BY count(*) DESC
  22. LIMIT :limit
  23. SQL
  24. end
  25. def earliest_status_id
  26. Mastodon::Snowflake.id_at(@start_at)
  27. end
  28. def latest_status_id
  29. Mastodon::Snowflake.id_at(@end_at)
  30. end
  31. end