1
0
Fork 0
forked from fedi/mastodon
mastodon/app/lib/admin/metrics/dimension/ips_dimension.rb
Eugen Rochko 7f4db65217 WIP
2022-08-16 01:00:23 +02:00

24 lines
614 B
Ruby

# frozen_string_literal: true
class Admin::Metrics::Dimension::IPsDimension < Admin::Metrics::Dimension::BaseDimension
def key
'ips'
end
protected
def perform_query
sql = <<-SQL.squish
SELECT sign_up_ip, count(*) AS value
FROM users
WHERE created_at BETWEEN $1 AND $2
GROUP BY sign_up_ip
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['sign_up_ip'], human_key: row['sign_up_ip'], value: row['value'].to_s } }
end
end