2022-03-09 07:52:32 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class Admin::Metrics::Measure::InstanceAccountsMeasure < Admin::Metrics::Measure::BaseMeasure
|
2023-06-05 18:46:04 +00:00
|
|
|
include Admin::Metrics::Measure::QueryHelper
|
|
|
|
|
2022-03-09 07:52:32 +00:00
|
|
|
def self.with_params?
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
|
|
|
def key
|
|
|
|
'instance_accounts'
|
|
|
|
end
|
|
|
|
|
|
|
|
def total_in_time_range?
|
|
|
|
false
|
|
|
|
end
|
|
|
|
|
|
|
|
protected
|
|
|
|
|
|
|
|
def perform_total_query
|
2023-06-01 07:37:38 +00:00
|
|
|
domain = params[:domain]
|
|
|
|
domain = Instance.by_domain_and_subdomains(params[:domain]).select(:domain) if params[:include_subdomains]
|
|
|
|
Account.where(domain: domain).count
|
2022-03-09 07:52:32 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def perform_previous_total_query
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
|
2023-06-05 18:46:04 +00:00
|
|
|
def sql_array
|
|
|
|
[sql_query_string, { start_at: @start_at, end_at: @end_at, domain: params[:domain] }]
|
|
|
|
end
|
2023-06-01 07:37:38 +00:00
|
|
|
|
2023-06-05 18:46:04 +00:00
|
|
|
def sql_query_string
|
|
|
|
<<~SQL.squish
|
2022-03-09 07:52:32 +00:00
|
|
|
SELECT axis.*, (
|
|
|
|
WITH new_accounts AS (
|
|
|
|
SELECT accounts.id
|
|
|
|
FROM accounts
|
|
|
|
WHERE date_trunc('day', accounts.created_at)::date = axis.period
|
2023-06-05 18:46:04 +00:00
|
|
|
AND #{account_domain_sql(params[:include_subdomains])}
|
2022-03-09 07:52:32 +00:00
|
|
|
)
|
|
|
|
SELECT count(*) FROM new_accounts
|
|
|
|
) AS value
|
|
|
|
FROM (
|
2024-06-11 07:42:15 +00:00
|
|
|
#{generated_series_days}
|
2022-03-09 07:52:32 +00:00
|
|
|
) AS axis
|
|
|
|
SQL
|
|
|
|
end
|
|
|
|
|
|
|
|
def params
|
2023-06-01 07:37:38 +00:00
|
|
|
@params.permit(:domain, :include_subdomains)
|
2022-03-09 07:52:32 +00:00
|
|
|
end
|
|
|
|
end
|