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