sources_dimension.rb 782 B

12345678910111213141516171819202122232425
  1. # frozen_string_literal: true
  2. class Admin::Metrics::Dimension::SourcesDimension < Admin::Metrics::Dimension::BaseDimension
  3. def key
  4. 'sources'
  5. end
  6. protected
  7. def perform_query
  8. sql = <<-SQL.squish
  9. SELECT oauth_applications.name, count(*) AS value
  10. FROM users
  11. LEFT JOIN oauth_applications ON oauth_applications.id = users.created_by_application_id
  12. WHERE users.created_at BETWEEN $1 AND $2
  13. GROUP BY oauth_applications.name
  14. ORDER BY count(*) DESC
  15. LIMIT $3
  16. SQL
  17. rows = ActiveRecord::Base.connection.select_all(sql, nil, [[nil, @start_at], [nil, @end_at], [nil, @limit]])
  18. rows.map { |row| { key: row['name'] || 'web', human_key: row['name'] || I18n.t('admin.dashboard.website'), value: row['value'].to_s } }
  19. end
  20. end