This repository has been archived on 2024-07-22. You can view files and clone it, but cannot push or open issues or pull requests.
2021-10-14 11:44:59 -07:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class Admin::Metrics::Dimension::SourcesDimension < Admin::Metrics::Dimension::BaseDimension
|
|
|
|
def key
|
|
|
|
'sources'
|
|
|
|
end
|
|
|
|
|
2022-02-22 06:27:08 -08:00
|
|
|
protected
|
|
|
|
|
|
|
|
def perform_query
|
2021-10-14 11:44:59 -07:00
|
|
|
sql = <<-SQL.squish
|
|
|
|
SELECT oauth_applications.name, count(*) AS value
|
|
|
|
FROM users
|
|
|
|
LEFT JOIN oauth_applications ON oauth_applications.id = users.created_by_application_id
|
|
|
|
WHERE users.created_at BETWEEN $1 AND $2
|
|
|
|
GROUP BY oauth_applications.name
|
|
|
|
ORDER BY count(*) DESC
|
|
|
|
LIMIT $3
|
|
|
|
SQL
|
|
|
|
|
|
|
|
rows = ActiveRecord::Base.connection.select_all(sql, nil, [[nil, @start_at], [nil, @end_at], [nil, @limit]])
|
|
|
|
|
|
|
|
rows.map { |row| { key: row['name'] || 'web', human_key: row['name'] || I18n.t('admin.dashboard.website'), value: row['value'].to_s } }
|
|
|
|
end
|
|
|
|
end
|