1
0
Fork 0
mirror of https://github.com/mastodon/mastodon.git synced 2024-08-20 21:08:15 -07:00
mastodon/app/lib/admin/metrics/measure/instance_statuses_measure.rb

55 lines
1.2 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
class Admin::Metrics::Measure::InstanceStatusesMeasure < Admin::Metrics::Measure::BaseMeasure
include Admin::Metrics::Measure::QueryHelper
def self.with_params?
true
end
def key
'instance_statuses'
end
def total_in_time_range?
false
end
protected
def perform_total_query
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
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))
end
def earliest_status_id
Mastodon::Snowflake.id_at(@start_at.beginning_of_day, with_random: false)
end
def latest_status_id
Mastodon::Snowflake.id_at(@end_at.end_of_day, with_random: false)
end
def params
@params.permit(:domain, :include_subdomains)
end
end