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