2022-03-08 23:52:32 -08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class Admin::Metrics::Measure::InstanceStatusesMeasure < Admin::Metrics::Measure::BaseMeasure
|
2023-06-05 11:46:04 -07:00
|
|
|
include Admin::Metrics::Measure::QueryHelper
|
|
|
|
|
2022-03-08 23:52:32 -08:00
|
|
|
def self.with_params?
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
|
|
|
def key
|
|
|
|
'instance_statuses'
|
|
|
|
end
|
|
|
|
|
|
|
|
def total_in_time_range?
|
|
|
|
false
|
|
|
|
end
|
|
|
|
|
|
|
|
protected
|
|
|
|
|
|
|
|
def perform_total_query
|
2023-06-01 00:37:38 -07:00
|
|
|
domain = params[:domain]
|
|
|
|
domain = Instance.by_domain_and_subdomains(params[:domain]).select(:domain) if params[:include_subdomains]
|
|
|
|
Status.joins(:account).merge(Account.where(domain: domain)).count
|
2022-03-08 23:52:32 -08:00
|
|
|
end
|
|
|
|
|
|
|
|
def perform_previous_total_query
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
|
2024-04-19 08:58:55 -07:00
|
|
|
def data_source_query
|
|
|
|
Status
|
|
|
|
.select(:id)
|
|
|
|
.joins(:account)
|
2024-06-11 08:30:45 -07:00
|
|
|
.where(account_domain_sql, domain: params[:domain])
|
2024-04-19 08:58:55 -07:00
|
|
|
.where(
|
2024-06-11 08:34:16 -07:00
|
|
|
<<~SQL.squish, earliest_status_id: earliest_status_id, latest_status_id: latest_status_id
|
2024-04-19 08:58:55 -07:00
|
|
|
statuses.id BETWEEN :earliest_status_id AND :latest_status_id
|
2024-06-11 06:56:55 -07:00
|
|
|
SQL
|
|
|
|
)
|
2024-06-11 07:20:38 -07:00
|
|
|
.where(daily_period(:statuses))
|
2023-06-05 11:46:04 -07:00
|
|
|
end
|
2022-03-08 23:52:32 -08:00
|
|
|
|
2023-06-05 11:46:04 -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 11:46:04 -07:00
|
|
|
end
|
2022-03-08 23:52:32 -08:00
|
|
|
|
2023-06-05 11:46:04 -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)
|
2022-03-08 23:52:32 -08:00
|
|
|
end
|
|
|
|
|
|
|
|
def params
|
2023-06-01 00:37:38 -07:00
|
|
|
@params.permit(:domain, :include_subdomains)
|
2022-03-08 23:52:32 -08:00
|
|
|
end
|
|
|
|
end
|