mirror of
https://github.com/mastodon/mastodon.git
synced 2024-12-21 00:29:47 +00:00
Extract method to generate series of days in measure sql classes (#29928)
This commit is contained in:
parent
edf6d64eeb
commit
88cfc4056d
|
@ -43,7 +43,7 @@ class Admin::Metrics::Measure::InstanceAccountsMeasure < Admin::Metrics::Measure
|
|||
SELECT count(*) FROM new_accounts
|
||||
) AS value
|
||||
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
|
||||
SQL
|
||||
end
|
||||
|
|
|
@ -44,7 +44,7 @@ class Admin::Metrics::Measure::InstanceFollowersMeasure < Admin::Metrics::Measur
|
|||
SELECT count(*) FROM new_followers
|
||||
) AS value
|
||||
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
|
||||
SQL
|
||||
end
|
||||
|
|
|
@ -44,7 +44,7 @@ class Admin::Metrics::Measure::InstanceFollowsMeasure < Admin::Metrics::Measure:
|
|||
SELECT count(*) FROM new_follows
|
||||
) AS value
|
||||
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
|
||||
SQL
|
||||
end
|
||||
|
|
|
@ -53,7 +53,7 @@ class Admin::Metrics::Measure::InstanceMediaAttachmentsMeasure < Admin::Metrics:
|
|||
SELECT COALESCE(SUM(size), 0) FROM new_media_attachments
|
||||
) AS value
|
||||
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
|
||||
SQL
|
||||
end
|
||||
|
|
|
@ -44,7 +44,7 @@ class Admin::Metrics::Measure::InstanceReportsMeasure < Admin::Metrics::Measure:
|
|||
SELECT count(*) FROM new_reports
|
||||
) AS value
|
||||
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
|
||||
SQL
|
||||
end
|
||||
|
|
|
@ -45,7 +45,7 @@ class Admin::Metrics::Measure::InstanceStatusesMeasure < Admin::Metrics::Measure
|
|||
SELECT count(*) FROM new_statuses
|
||||
) AS value
|
||||
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
|
||||
SQL
|
||||
end
|
||||
|
|
|
@ -32,7 +32,7 @@ class Admin::Metrics::Measure::NewUsersMeasure < Admin::Metrics::Measure::BaseMe
|
|||
SELECT count(*) FROM new_users
|
||||
) AS value
|
||||
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
|
||||
SQL
|
||||
end
|
||||
|
|
|
@ -32,7 +32,7 @@ class Admin::Metrics::Measure::OpenedReportsMeasure < Admin::Metrics::Measure::B
|
|||
SELECT count(*) FROM new_reports
|
||||
) AS value
|
||||
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
|
||||
SQL
|
||||
end
|
||||
|
|
|
@ -15,6 +15,14 @@ module Admin::Metrics::Measure::QueryHelper
|
|||
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))"
|
||||
|
|
|
@ -32,7 +32,7 @@ class Admin::Metrics::Measure::ResolvedReportsMeasure < Admin::Metrics::Measure:
|
|||
SELECT count(*) FROM resolved_reports
|
||||
) AS value
|
||||
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
|
||||
SQL
|
||||
end
|
||||
|
|
|
@ -40,7 +40,7 @@ class Admin::Metrics::Measure::TagServersMeasure < Admin::Metrics::Measure::Base
|
|||
SELECT COUNT(*) FROM tag_servers
|
||||
) AS value
|
||||
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
|
||||
SQL
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue