From 13888d827c6164fefcefade849b4773b1aa24a3a Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Tue, 11 Jun 2024 09:56:55 -0400 Subject: [PATCH] Isolate date trunc --- .../admin/metrics/measure/instance_accounts_measure.rb | 2 +- .../admin/metrics/measure/instance_followers_measure.rb | 2 +- app/lib/admin/metrics/measure/instance_follows_measure.rb | 2 +- app/lib/admin/metrics/measure/instance_reports_measure.rb | 2 +- .../admin/metrics/measure/instance_statuses_measure.rb | 8 ++++++-- 5 files changed, 10 insertions(+), 6 deletions(-) diff --git a/app/lib/admin/metrics/measure/instance_accounts_measure.rb b/app/lib/admin/metrics/measure/instance_accounts_measure.rb index 31c4fd28548..d669f5a7ee8 100644 --- a/app/lib/admin/metrics/measure/instance_accounts_measure.rb +++ b/app/lib/admin/metrics/measure/instance_accounts_measure.rb @@ -34,10 +34,10 @@ class Admin::Metrics::Measure::InstanceAccountsMeasure < Admin::Metrics::Measure def data_source_query Account .select(:id) + .where(account_domain_sql(params[:include_subdomains])) .where( <<~SQL.squish DATE_TRUNC('day', accounts.created_at)::date = axis.period - AND #{account_domain_sql(params[:include_subdomains])} SQL ).to_sql end diff --git a/app/lib/admin/metrics/measure/instance_followers_measure.rb b/app/lib/admin/metrics/measure/instance_followers_measure.rb index b5e61123831..9cbd8a2392b 100644 --- a/app/lib/admin/metrics/measure/instance_followers_measure.rb +++ b/app/lib/admin/metrics/measure/instance_followers_measure.rb @@ -35,10 +35,10 @@ class Admin::Metrics::Measure::InstanceFollowersMeasure < Admin::Metrics::Measur Follow .select(:id) .joins(:account) + .where(account_domain_sql(params[:include_subdomains])) .where( <<~SQL.squish DATE_TRUNC('day', follows.created_at)::date = axis.period - AND #{account_domain_sql(params[:include_subdomains])} SQL ).to_sql end diff --git a/app/lib/admin/metrics/measure/instance_follows_measure.rb b/app/lib/admin/metrics/measure/instance_follows_measure.rb index fe7fbdf4d09..c219b8354fe 100644 --- a/app/lib/admin/metrics/measure/instance_follows_measure.rb +++ b/app/lib/admin/metrics/measure/instance_follows_measure.rb @@ -35,10 +35,10 @@ class Admin::Metrics::Measure::InstanceFollowsMeasure < Admin::Metrics::Measure: Follow .select(:id) .joins(:target_account) + .where(account_domain_sql(params[:include_subdomains])) .where( <<~SQL.squish DATE_TRUNC('day', follows.created_at)::date = axis.period - AND #{account_domain_sql(params[:include_subdomains])} SQL ).to_sql end diff --git a/app/lib/admin/metrics/measure/instance_reports_measure.rb b/app/lib/admin/metrics/measure/instance_reports_measure.rb index 757678690a9..519a50b6f77 100644 --- a/app/lib/admin/metrics/measure/instance_reports_measure.rb +++ b/app/lib/admin/metrics/measure/instance_reports_measure.rb @@ -35,10 +35,10 @@ class Admin::Metrics::Measure::InstanceReportsMeasure < Admin::Metrics::Measure: Report .select(:id) .joins(:target_account) + .where(account_domain_sql(params[:include_subdomains])) .where( <<~SQL.squish DATE_TRUNC('day', reports.created_at)::date = axis.period - AND #{account_domain_sql(params[:include_subdomains])} SQL ).to_sql end diff --git a/app/lib/admin/metrics/measure/instance_statuses_measure.rb b/app/lib/admin/metrics/measure/instance_statuses_measure.rb index 30b025c00ab..73dea4d5c48 100644 --- a/app/lib/admin/metrics/measure/instance_statuses_measure.rb +++ b/app/lib/admin/metrics/measure/instance_statuses_measure.rb @@ -35,11 +35,15 @@ class Admin::Metrics::Measure::InstanceStatusesMeasure < Admin::Metrics::Measure Status .select(:id) .joins(:account) + .where(account_domain_sql(params[:include_subdomains])) .where( <<~SQL.squish statuses.id BETWEEN :earliest_status_id AND :latest_status_id - AND #{account_domain_sql(params[:include_subdomains])} - AND date_trunc('day', statuses.created_at)::date = axis.period + SQL + ) + .where( + <<~SQL.squish + date_trunc('day', statuses.created_at)::date = axis.period SQL ).to_sql end