servers_dimension.rb 821 B

12345678910111213141516171819202122232425
  1. # frozen_string_literal: true
  2. class Admin::Metrics::Dimension::ServersDimension < Admin::Metrics::Dimension::BaseDimension
  3. def key
  4. 'servers'
  5. end
  6. protected
  7. def perform_query
  8. sql = <<-SQL.squish
  9. SELECT accounts.domain, count(*) AS value
  10. FROM statuses
  11. INNER JOIN accounts ON accounts.id = statuses.account_id
  12. WHERE statuses.id BETWEEN $1 AND $2
  13. GROUP BY accounts.domain
  14. ORDER BY count(*) DESC
  15. LIMIT $3
  16. SQL
  17. rows = ActiveRecord::Base.connection.select_all(sql, nil, [[nil, Mastodon::Snowflake.id_at(@start_at)], [nil, Mastodon::Snowflake.id_at(@end_at)], [nil, @limit]])
  18. 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 } }
  19. end
  20. end