Extract method to generate series of days in measure sql classes (#29928)

This commit is contained in:
Matt Jankowski 2024-06-11 03:42:15 -04:00 committed by GitHub
parent edf6d64eeb
commit 88cfc4056d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
11 changed files with 18 additions and 10 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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))"

View File

@ -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

View File

@ -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