mirror of
https://github.com/mastodon/mastodon
synced 2024-12-13 22:28:23 +09:00
34 lines
830 B
Ruby
34 lines
830 B
Ruby
# frozen_string_literal: true
|
|
|
|
module Admin::Metrics::Measure::QueryHelper
|
|
protected
|
|
|
|
def perform_data_query
|
|
measurement_data_rows.map { |row| { date: row['period'], value: row['value'].to_s } }
|
|
end
|
|
|
|
def measurement_data_rows
|
|
ActiveRecord::Base.connection.select_all(sanitized_sql_string)
|
|
end
|
|
|
|
def sanitized_sql_string
|
|
ActiveRecord::Base.sanitize_sql_array(sql_array)
|
|
end
|
|
|
|
def generated_series_days
|
|
Arel.sql(
|
|
<<~SQL.squish
|
|
SELECT generate_series(timestamp :start_at, :end_at, '1 day')::date AS period
|
|
SQL
|
|
)
|
|
end
|
|
|
|
def account_domain_sql(include_subdomains)
|
|
if include_subdomains
|
|
"accounts.domain IN (SELECT domain FROM instances WHERE reverse('.' || domain) LIKE reverse('.' || :domain::text))"
|
|
else
|
|
'accounts.domain = :domain::text'
|
|
end
|
|
end
|
|
end
|