Extract method to generate series of days in measure sql classes (#29928)
parent
edf6d64eeb
commit
88cfc4056d
|
@ -43,7 +43,7 @@ class Admin::Metrics::Measure::InstanceAccountsMeasure < Admin::Metrics::Measure
|
||||||
SELECT count(*) FROM new_accounts
|
SELECT count(*) FROM new_accounts
|
||||||
) AS value
|
) AS value
|
||||||
FROM (
|
FROM (
|
||||||
SELECT generate_series(date_trunc('day', :start_at::timestamp)::date, date_trunc('day', :end_at::timestamp)::date, interval '1 day') AS period
|
#{generated_series_days}
|
||||||
) AS axis
|
) AS axis
|
||||||
SQL
|
SQL
|
||||||
end
|
end
|
||||||
|
|
|
@ -44,7 +44,7 @@ class Admin::Metrics::Measure::InstanceFollowersMeasure < Admin::Metrics::Measur
|
||||||
SELECT count(*) FROM new_followers
|
SELECT count(*) FROM new_followers
|
||||||
) AS value
|
) AS value
|
||||||
FROM (
|
FROM (
|
||||||
SELECT generate_series(date_trunc('day', :start_at::timestamp)::date, date_trunc('day', :end_at::timestamp)::date, interval '1 day') AS period
|
#{generated_series_days}
|
||||||
) AS axis
|
) AS axis
|
||||||
SQL
|
SQL
|
||||||
end
|
end
|
||||||
|
|
|
@ -44,7 +44,7 @@ class Admin::Metrics::Measure::InstanceFollowsMeasure < Admin::Metrics::Measure:
|
||||||
SELECT count(*) FROM new_follows
|
SELECT count(*) FROM new_follows
|
||||||
) AS value
|
) AS value
|
||||||
FROM (
|
FROM (
|
||||||
SELECT generate_series(date_trunc('day', :start_at::timestamp)::date, date_trunc('day', :end_at::timestamp)::date, interval '1 day') AS period
|
#{generated_series_days}
|
||||||
) AS axis
|
) AS axis
|
||||||
SQL
|
SQL
|
||||||
end
|
end
|
||||||
|
|
|
@ -53,7 +53,7 @@ class Admin::Metrics::Measure::InstanceMediaAttachmentsMeasure < Admin::Metrics:
|
||||||
SELECT COALESCE(SUM(size), 0) FROM new_media_attachments
|
SELECT COALESCE(SUM(size), 0) FROM new_media_attachments
|
||||||
) AS value
|
) AS value
|
||||||
FROM (
|
FROM (
|
||||||
SELECT generate_series(date_trunc('day', :start_at::timestamp)::date, date_trunc('day', :end_at::timestamp)::date, interval '1 day') AS period
|
#{generated_series_days}
|
||||||
) AS axis
|
) AS axis
|
||||||
SQL
|
SQL
|
||||||
end
|
end
|
||||||
|
|
|
@ -44,7 +44,7 @@ class Admin::Metrics::Measure::InstanceReportsMeasure < Admin::Metrics::Measure:
|
||||||
SELECT count(*) FROM new_reports
|
SELECT count(*) FROM new_reports
|
||||||
) AS value
|
) AS value
|
||||||
FROM (
|
FROM (
|
||||||
SELECT generate_series(date_trunc('day', :start_at::timestamp)::date, date_trunc('day', :end_at::timestamp)::date, interval '1 day') AS period
|
#{generated_series_days}
|
||||||
) AS axis
|
) AS axis
|
||||||
SQL
|
SQL
|
||||||
end
|
end
|
||||||
|
|
|
@ -45,7 +45,7 @@ class Admin::Metrics::Measure::InstanceStatusesMeasure < Admin::Metrics::Measure
|
||||||
SELECT count(*) FROM new_statuses
|
SELECT count(*) FROM new_statuses
|
||||||
) AS value
|
) AS value
|
||||||
FROM (
|
FROM (
|
||||||
SELECT generate_series(date_trunc('day', :start_at::timestamp)::date, date_trunc('day', :end_at::timestamp)::date, interval '1 day') AS period
|
#{generated_series_days}
|
||||||
) AS axis
|
) AS axis
|
||||||
SQL
|
SQL
|
||||||
end
|
end
|
||||||
|
|
|
@ -32,7 +32,7 @@ class Admin::Metrics::Measure::NewUsersMeasure < Admin::Metrics::Measure::BaseMe
|
||||||
SELECT count(*) FROM new_users
|
SELECT count(*) FROM new_users
|
||||||
) AS value
|
) AS value
|
||||||
FROM (
|
FROM (
|
||||||
SELECT generate_series(date_trunc('day', :start_at::timestamp)::date, date_trunc('day', :end_at::timestamp)::date, interval '1 day') AS period
|
#{generated_series_days}
|
||||||
) AS axis
|
) AS axis
|
||||||
SQL
|
SQL
|
||||||
end
|
end
|
||||||
|
|
|
@ -32,7 +32,7 @@ class Admin::Metrics::Measure::OpenedReportsMeasure < Admin::Metrics::Measure::B
|
||||||
SELECT count(*) FROM new_reports
|
SELECT count(*) FROM new_reports
|
||||||
) AS value
|
) AS value
|
||||||
FROM (
|
FROM (
|
||||||
SELECT generate_series(date_trunc('day', :start_at::timestamp)::date, date_trunc('day', :end_at::timestamp)::date, interval '1 day') AS period
|
#{generated_series_days}
|
||||||
) AS axis
|
) AS axis
|
||||||
SQL
|
SQL
|
||||||
end
|
end
|
||||||
|
|
|
@ -15,6 +15,14 @@ module Admin::Metrics::Measure::QueryHelper
|
||||||
ActiveRecord::Base.sanitize_sql_array(sql_array)
|
ActiveRecord::Base.sanitize_sql_array(sql_array)
|
||||||
end
|
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)
|
def account_domain_sql(include_subdomains)
|
||||||
if include_subdomains
|
if include_subdomains
|
||||||
"accounts.domain IN (SELECT domain FROM instances WHERE reverse('.' || domain) LIKE reverse('.' || :domain::text))"
|
"accounts.domain IN (SELECT domain FROM instances WHERE reverse('.' || domain) LIKE reverse('.' || :domain::text))"
|
||||||
|
|
|
@ -32,7 +32,7 @@ class Admin::Metrics::Measure::ResolvedReportsMeasure < Admin::Metrics::Measure:
|
||||||
SELECT count(*) FROM resolved_reports
|
SELECT count(*) FROM resolved_reports
|
||||||
) AS value
|
) AS value
|
||||||
FROM (
|
FROM (
|
||||||
SELECT generate_series(date_trunc('day', :start_at::timestamp)::date, date_trunc('day', :end_at::timestamp)::date, interval '1 day') AS period
|
#{generated_series_days}
|
||||||
) AS axis
|
) AS axis
|
||||||
SQL
|
SQL
|
||||||
end
|
end
|
||||||
|
|
|
@ -40,7 +40,7 @@ class Admin::Metrics::Measure::TagServersMeasure < Admin::Metrics::Measure::Base
|
||||||
SELECT COUNT(*) FROM tag_servers
|
SELECT COUNT(*) FROM tag_servers
|
||||||
) AS value
|
) AS value
|
||||||
FROM (
|
FROM (
|
||||||
SELECT generate_series(date_trunc('day', :start_at::timestamp)::date, date_trunc('day', :end_at::timestamp)::date, interval '1 day') AS period
|
#{generated_series_days}
|
||||||
) as axis
|
) as axis
|
||||||
SQL
|
SQL
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue