2021-10-14 18:44:59 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class Admin::Metrics::Dimension::ServersDimension < Admin::Metrics::Dimension::BaseDimension
|
2023-06-05 14:52:33 +00:00
|
|
|
include Admin::Metrics::Dimension::QueryHelper
|
|
|
|
|
2021-10-14 18:44:59 +00:00
|
|
|
def key
|
|
|
|
'servers'
|
|
|
|
end
|
|
|
|
|
2022-02-22 14:27:08 +00:00
|
|
|
protected
|
|
|
|
|
|
|
|
def perform_query
|
2023-06-05 14:52:33 +00:00
|
|
|
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 } }
|
|
|
|
end
|
|
|
|
|
|
|
|
def sql_array
|
|
|
|
[sql_query_string, { earliest_status_id: earliest_status_id, latest_status_id: latest_status_id, limit: @limit }]
|
|
|
|
end
|
|
|
|
|
|
|
|
def sql_query_string
|
|
|
|
<<~SQL.squish
|
2021-10-14 18:44:59 +00:00
|
|
|
SELECT accounts.domain, count(*) AS value
|
|
|
|
FROM statuses
|
|
|
|
INNER JOIN accounts ON accounts.id = statuses.account_id
|
2023-06-05 14:52:33 +00:00
|
|
|
WHERE statuses.id BETWEEN :earliest_status_id AND :latest_status_id
|
2021-10-14 18:44:59 +00:00
|
|
|
GROUP BY accounts.domain
|
|
|
|
ORDER BY count(*) DESC
|
2023-06-05 14:52:33 +00:00
|
|
|
LIMIT :limit
|
2021-10-14 18:44:59 +00:00
|
|
|
SQL
|
2023-06-05 14:52:33 +00:00
|
|
|
end
|
2021-10-14 18:44:59 +00:00
|
|
|
|
2023-06-05 14:52:33 +00:00
|
|
|
def earliest_status_id
|
|
|
|
Mastodon::Snowflake.id_at(@start_at)
|
|
|
|
end
|
2021-10-14 18:44:59 +00:00
|
|
|
|
2023-06-05 14:52:33 +00:00
|
|
|
def latest_status_id
|
|
|
|
Mastodon::Snowflake.id_at(@end_at)
|
2021-10-14 18:44:59 +00:00
|
|
|
end
|
|
|
|
end
|