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