From e2a243ae311c76464633c4045bc9c048cce58b69 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Fri, 19 Apr 2024 11:58:55 -0400 Subject: [PATCH 01/17] First pass at interface improvement --- .../measure/instance_accounts_measure.rb | 22 ++++++--------- .../measure/instance_followers_measure.rb | 24 ++++++---------- .../measure/instance_follows_measure.rb | 24 ++++++---------- .../instance_media_attachments_measure.rb | 26 ++++++++--------- .../measure/instance_reports_measure.rb | 24 ++++++---------- .../measure/instance_statuses_measure.rb | 28 ++++++++----------- .../metrics/measure/new_users_measure.rb | 22 ++++++--------- .../metrics/measure/opened_reports_measure.rb | 22 ++++++--------- app/lib/admin/metrics/measure/query_helper.rb | 20 +++++++++---- .../measure/resolved_reports_measure.rb | 22 ++++++--------- .../metrics/measure/tag_servers_measure.rb | 24 ++++++---------- 11 files changed, 105 insertions(+), 153 deletions(-) diff --git a/app/lib/admin/metrics/measure/instance_accounts_measure.rb b/app/lib/admin/metrics/measure/instance_accounts_measure.rb index 889a5e6f05f..31c4fd28548 100644 --- a/app/lib/admin/metrics/measure/instance_accounts_measure.rb +++ b/app/lib/admin/metrics/measure/instance_accounts_measure.rb @@ -31,21 +31,15 @@ class Admin::Metrics::Measure::InstanceAccountsMeasure < Admin::Metrics::Measure [sql_query_string, { start_at: @start_at, end_at: @end_at, domain: params[:domain] }] end - def sql_query_string - <<~SQL.squish - SELECT axis.*, ( - WITH new_accounts AS ( - SELECT accounts.id - FROM accounts - WHERE date_trunc('day', accounts.created_at)::date = axis.period + def data_source_query + Account + .select(:id) + .where( + <<~SQL.squish + DATE_TRUNC('day', accounts.created_at)::date = axis.period AND #{account_domain_sql(params[:include_subdomains])} - ) - SELECT count(*) FROM new_accounts - ) AS value - FROM ( - #{generated_series_days} - ) AS axis - SQL + SQL + ).to_sql end def params diff --git a/app/lib/admin/metrics/measure/instance_followers_measure.rb b/app/lib/admin/metrics/measure/instance_followers_measure.rb index fa934c6b96c..b5e61123831 100644 --- a/app/lib/admin/metrics/measure/instance_followers_measure.rb +++ b/app/lib/admin/metrics/measure/instance_followers_measure.rb @@ -31,22 +31,16 @@ class Admin::Metrics::Measure::InstanceFollowersMeasure < Admin::Metrics::Measur [sql_query_string, { start_at: @start_at, end_at: @end_at, domain: params[:domain] }] end - def sql_query_string - <<~SQL.squish - SELECT axis.*, ( - WITH new_followers AS ( - SELECT follows.id - FROM follows - INNER JOIN accounts ON follows.account_id = accounts.id - WHERE date_trunc('day', follows.created_at)::date = axis.period + def data_source_query + Follow + .select(:id) + .joins(:account) + .where( + <<~SQL.squish + DATE_TRUNC('day', follows.created_at)::date = axis.period AND #{account_domain_sql(params[:include_subdomains])} - ) - SELECT count(*) FROM new_followers - ) AS value - FROM ( - #{generated_series_days} - ) AS axis - SQL + SQL + ).to_sql end def params diff --git a/app/lib/admin/metrics/measure/instance_follows_measure.rb b/app/lib/admin/metrics/measure/instance_follows_measure.rb index 3f3ab73fc90..fe7fbdf4d09 100644 --- a/app/lib/admin/metrics/measure/instance_follows_measure.rb +++ b/app/lib/admin/metrics/measure/instance_follows_measure.rb @@ -31,22 +31,16 @@ class Admin::Metrics::Measure::InstanceFollowsMeasure < Admin::Metrics::Measure: [sql_query_string, { start_at: @start_at, end_at: @end_at, domain: params[:domain] }] end - def sql_query_string - <<~SQL.squish - SELECT axis.*, ( - WITH new_follows AS ( - SELECT follows.id - FROM follows - INNER JOIN accounts ON follows.target_account_id = accounts.id - WHERE date_trunc('day', follows.created_at)::date = axis.period + def data_source_query + Follow + .select(:id) + .joins(:target_account) + .where( + <<~SQL.squish + DATE_TRUNC('day', follows.created_at)::date = axis.period AND #{account_domain_sql(params[:include_subdomains])} - ) - SELECT count(*) FROM new_follows - ) AS value - FROM ( - #{generated_series_days} - ) AS axis - SQL + SQL + ).to_sql end def params diff --git a/app/lib/admin/metrics/measure/instance_media_attachments_measure.rb b/app/lib/admin/metrics/measure/instance_media_attachments_measure.rb index 996ca52e0bb..03204329cd9 100644 --- a/app/lib/admin/metrics/measure/instance_media_attachments_measure.rb +++ b/app/lib/admin/metrics/measure/instance_media_attachments_measure.rb @@ -40,21 +40,19 @@ class Admin::Metrics::Measure::InstanceMediaAttachmentsMeasure < Admin::Metrics: [sql_query_string, { start_at: @start_at, end_at: @end_at, domain: params[:domain] }] end - def sql_query_string + def data_source_query <<~SQL.squish - SELECT axis.*, ( - WITH new_media_attachments AS ( - SELECT COALESCE(media_attachments.file_file_size, 0) + COALESCE(media_attachments.thumbnail_file_size, 0) AS size - FROM media_attachments - INNER JOIN accounts ON accounts.id = media_attachments.account_id - WHERE date_trunc('day', media_attachments.created_at)::date = axis.period - AND #{account_domain_sql(params[:include_subdomains])} - ) - SELECT COALESCE(SUM(size), 0) FROM new_media_attachments - ) AS value - FROM ( - #{generated_series_days} - ) AS axis + SELECT COALESCE(media_attachments.file_file_size, 0) + COALESCE(media_attachments.thumbnail_file_size, 0) AS size + FROM media_attachments + INNER JOIN accounts ON accounts.id = media_attachments.account_id + WHERE date_trunc('day', media_attachments.created_at)::date = axis.period + AND #{account_domain_sql(params[:include_subdomains])} + SQL + end + + def select_target + <<~SQL.squish + COALESCE(SUM(size), 0) 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 ae1bb6e68de..757678690a9 100644 --- a/app/lib/admin/metrics/measure/instance_reports_measure.rb +++ b/app/lib/admin/metrics/measure/instance_reports_measure.rb @@ -31,22 +31,16 @@ class Admin::Metrics::Measure::InstanceReportsMeasure < Admin::Metrics::Measure: [sql_query_string, { start_at: @start_at, end_at: @end_at, domain: params[:domain] }] end - def sql_query_string - <<~SQL.squish - SELECT axis.*, ( - WITH new_reports AS ( - SELECT reports.id - FROM reports - INNER JOIN accounts ON accounts.id = reports.target_account_id - WHERE date_trunc('day', reports.created_at)::date = axis.period + def data_source_query + Report + .select(:id) + .joins(:target_account) + .where( + <<~SQL.squish + DATE_TRUNC('day', reports.created_at)::date = axis.period AND #{account_domain_sql(params[:include_subdomains])} - ) - SELECT count(*) FROM new_reports - ) AS value - FROM ( - #{generated_series_days} - ) AS axis - SQL + SQL + ).to_sql end def params diff --git a/app/lib/admin/metrics/measure/instance_statuses_measure.rb b/app/lib/admin/metrics/measure/instance_statuses_measure.rb index 324d427b18b..30b025c00ab 100644 --- a/app/lib/admin/metrics/measure/instance_statuses_measure.rb +++ b/app/lib/admin/metrics/measure/instance_statuses_measure.rb @@ -31,23 +31,17 @@ class Admin::Metrics::Measure::InstanceStatusesMeasure < Admin::Metrics::Measure [sql_query_string, { start_at: @start_at, end_at: @end_at, domain: params[:domain], earliest_status_id: earliest_status_id, latest_status_id: latest_status_id }] end - def sql_query_string - <<~SQL.squish - SELECT axis.*, ( - WITH new_statuses AS ( - SELECT statuses.id - FROM statuses - INNER JOIN accounts ON accounts.id = statuses.account_id - WHERE 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 - ) - SELECT count(*) FROM new_statuses - ) AS value - FROM ( - #{generated_series_days} - ) AS axis - SQL + def data_source_query + Status + .select(:id) + .joins(:account) + .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 + ).to_sql end def earliest_status_id diff --git a/app/lib/admin/metrics/measure/new_users_measure.rb b/app/lib/admin/metrics/measure/new_users_measure.rb index 32057154d6b..66334cd11c8 100644 --- a/app/lib/admin/metrics/measure/new_users_measure.rb +++ b/app/lib/admin/metrics/measure/new_users_measure.rb @@ -21,19 +21,13 @@ class Admin::Metrics::Measure::NewUsersMeasure < Admin::Metrics::Measure::BaseMe [sql_query_string, { start_at: @start_at, end_at: @end_at }] end - def sql_query_string - <<~SQL.squish - SELECT axis.*, ( - WITH new_users AS ( - SELECT users.id - FROM users - WHERE date_trunc('day', users.created_at)::date = axis.period - ) - SELECT count(*) FROM new_users - ) AS value - FROM ( - #{generated_series_days} - ) AS axis - SQL + def data_source_query + User + .select(:id) + .where( + <<~SQL.squish + DATE_TRUNC('day', users.created_at)::date = axis.period + SQL + ).to_sql end end diff --git a/app/lib/admin/metrics/measure/opened_reports_measure.rb b/app/lib/admin/metrics/measure/opened_reports_measure.rb index 47de38bbe64..9628dd5c7da 100644 --- a/app/lib/admin/metrics/measure/opened_reports_measure.rb +++ b/app/lib/admin/metrics/measure/opened_reports_measure.rb @@ -21,19 +21,13 @@ class Admin::Metrics::Measure::OpenedReportsMeasure < Admin::Metrics::Measure::B [sql_query_string, { start_at: @start_at, end_at: @end_at }] end - def sql_query_string - <<~SQL.squish - SELECT axis.*, ( - WITH new_reports AS ( - SELECT reports.id - FROM reports - WHERE date_trunc('day', reports.created_at)::date = axis.period - ) - SELECT count(*) FROM new_reports - ) AS value - FROM ( - #{generated_series_days} - ) AS axis - SQL + def data_source_query + Report + .select(:id) + .where( + <<~SQL.squish + DATE_TRUNC('day', reports.created_at)::date = axis.period + SQL + ).to_sql end end diff --git a/app/lib/admin/metrics/measure/query_helper.rb b/app/lib/admin/metrics/measure/query_helper.rb index 47cfc63e5c5..4145f3fa442 100644 --- a/app/lib/admin/metrics/measure/query_helper.rb +++ b/app/lib/admin/metrics/measure/query_helper.rb @@ -15,12 +15,22 @@ module Admin::Metrics::Measure::QueryHelper ActiveRecord::Base.sanitize_sql_array(sql_array) end - def generated_series_days - Arel.sql( - <<~SQL.squish + def sql_query_string + <<~SQL.squish + SELECT axis.*, ( + WITH data_source AS (#{data_source_query}) + SELECT #{select_target} FROM data_source + ) AS value + FROM ( SELECT generate_series(:start_at::timestamp, :end_at::timestamp, '1 day')::date AS period - SQL - ) + ) AS axis + SQL + end + + def select_target + <<~SQL.squish + COUNT(*) + SQL end def account_domain_sql(include_subdomains) diff --git a/app/lib/admin/metrics/measure/resolved_reports_measure.rb b/app/lib/admin/metrics/measure/resolved_reports_measure.rb index ecfd779c86a..5c7b1c320fd 100644 --- a/app/lib/admin/metrics/measure/resolved_reports_measure.rb +++ b/app/lib/admin/metrics/measure/resolved_reports_measure.rb @@ -21,19 +21,13 @@ class Admin::Metrics::Measure::ResolvedReportsMeasure < Admin::Metrics::Measure: [sql_query_string, { start_at: @start_at, end_at: @end_at }] end - def sql_query_string - <<~SQL.squish - SELECT axis.*, ( - WITH resolved_reports AS ( - SELECT reports.id - FROM reports - WHERE date_trunc('day', reports.action_taken_at)::date = axis.period - ) - SELECT count(*) FROM resolved_reports - ) AS value - FROM ( - #{generated_series_days} - ) AS axis - SQL + def data_source_query + Report + .select(:id) + .where( + <<~SQL.squish + DATE_TRUNC('day', reports.action_taken_at)::date = axis.period + SQL + ).to_sql end end diff --git a/app/lib/admin/metrics/measure/tag_servers_measure.rb b/app/lib/admin/metrics/measure/tag_servers_measure.rb index 5db1076062b..897067703c1 100644 --- a/app/lib/admin/metrics/measure/tag_servers_measure.rb +++ b/app/lib/admin/metrics/measure/tag_servers_measure.rb @@ -25,23 +25,15 @@ class Admin::Metrics::Measure::TagServersMeasure < Admin::Metrics::Measure::Base [sql_query_string, { start_at: @start_at, end_at: @end_at, tag_id: tag.id, earliest_status_id: earliest_status_id, latest_status_id: latest_status_id }] end - def sql_query_string + def data_source_query <<~SQL.squish - SELECT axis.*, ( - WITH tag_servers AS ( - SELECT DISTINCT accounts.domain - FROM statuses - INNER JOIN statuses_tags ON statuses.id = statuses_tags.status_id - INNER JOIN accounts ON statuses.account_id = accounts.id - WHERE statuses_tags.tag_id = :tag_id - AND statuses.id BETWEEN :earliest_status_id AND :latest_status_id - AND date_trunc('day', statuses.created_at)::date = axis.period - ) - SELECT COUNT(*) FROM tag_servers - ) AS value - FROM ( - #{generated_series_days} - ) as axis + SELECT DISTINCT accounts.domain + FROM statuses + INNER JOIN statuses_tags ON statuses.id = statuses_tags.status_id + INNER JOIN accounts ON statuses.account_id = accounts.id + WHERE statuses_tags.tag_id = :tag_id + AND statuses.id BETWEEN :earliest_status_id AND :latest_status_id + AND date_trunc('day', statuses.created_at)::date = axis.period SQL end From 13888d827c6164fefcefade849b4773b1aa24a3a Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Tue, 11 Jun 2024 09:56:55 -0400 Subject: [PATCH 02/17] 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 From c570eca3932661e61c789c177bc89fb4852c8bde Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Tue, 11 Jun 2024 10:10:55 -0400 Subject: [PATCH 03/17] Use AR to build --- .../instance_media_attachments_measure.rb | 16 ++++++------ .../metrics/measure/tag_servers_measure.rb | 25 ++++++++++++------- 2 files changed, 25 insertions(+), 16 deletions(-) diff --git a/app/lib/admin/metrics/measure/instance_media_attachments_measure.rb b/app/lib/admin/metrics/measure/instance_media_attachments_measure.rb index 03204329cd9..c6abb9a0006 100644 --- a/app/lib/admin/metrics/measure/instance_media_attachments_measure.rb +++ b/app/lib/admin/metrics/measure/instance_media_attachments_measure.rb @@ -41,13 +41,15 @@ class Admin::Metrics::Measure::InstanceMediaAttachmentsMeasure < Admin::Metrics: end def data_source_query - <<~SQL.squish - SELECT COALESCE(media_attachments.file_file_size, 0) + COALESCE(media_attachments.thumbnail_file_size, 0) AS size - FROM media_attachments - INNER JOIN accounts ON accounts.id = media_attachments.account_id - WHERE date_trunc('day', media_attachments.created_at)::date = axis.period - AND #{account_domain_sql(params[:include_subdomains])} - SQL + MediaAttachment + .select('COALESCE(media_attachments.file_file_size, 0) + COALESCE(media_attachments.thumbnail_file_size, 0) AS size') + .joins(:account) + .where(account_domain_sql(params[:include_subdomains])) + .where( + <<~SQL.squish + DATE_TRUNC('day', media_attachments.created_at)::date = axis.period + SQL + ).to_sql end def select_target diff --git a/app/lib/admin/metrics/measure/tag_servers_measure.rb b/app/lib/admin/metrics/measure/tag_servers_measure.rb index 897067703c1..5eca9813d5a 100644 --- a/app/lib/admin/metrics/measure/tag_servers_measure.rb +++ b/app/lib/admin/metrics/measure/tag_servers_measure.rb @@ -26,15 +26,22 @@ class Admin::Metrics::Measure::TagServersMeasure < Admin::Metrics::Measure::Base end def data_source_query - <<~SQL.squish - SELECT DISTINCT accounts.domain - FROM statuses - INNER JOIN statuses_tags ON statuses.id = statuses_tags.status_id - INNER JOIN accounts ON statuses.account_id = accounts.id - WHERE statuses_tags.tag_id = :tag_id - AND statuses.id BETWEEN :earliest_status_id AND :latest_status_id - AND date_trunc('day', statuses.created_at)::date = axis.period - SQL + Status + .select('accounts.domain') + .distinct + .reorder(nil) + .joins(:tags, :account) + .where( + <<~SQL.squish + statuses_tags.tag_id = :tag_id + AND statuses.id BETWEEN :earliest_status_id AND :latest_status_id + SQL + ) + .where( + <<~SQL.squish + date_trunc('day', statuses.created_at)::date = axis.period + SQL + ).to_sql end def earliest_status_id From f1e35a60e6eaba20afb1c4f789d153fc03dcc0d3 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Tue, 11 Jun 2024 10:20:38 -0400 Subject: [PATCH 04/17] Method for date trunc compare --- app/lib/admin/metrics/measure/instance_accounts_measure.rb | 7 ++----- .../admin/metrics/measure/instance_followers_measure.rb | 7 ++----- app/lib/admin/metrics/measure/instance_follows_measure.rb | 7 ++----- .../metrics/measure/instance_media_attachments_measure.rb | 7 ++----- app/lib/admin/metrics/measure/instance_reports_measure.rb | 7 ++----- app/lib/admin/metrics/measure/instance_statuses_measure.rb | 7 ++----- app/lib/admin/metrics/measure/new_users_measure.rb | 7 ++----- app/lib/admin/metrics/measure/query_helper.rb | 6 ++++++ app/lib/admin/metrics/measure/resolved_reports_measure.rb | 7 ++----- app/lib/admin/metrics/measure/tag_servers_measure.rb | 7 ++----- 10 files changed, 24 insertions(+), 45 deletions(-) diff --git a/app/lib/admin/metrics/measure/instance_accounts_measure.rb b/app/lib/admin/metrics/measure/instance_accounts_measure.rb index d669f5a7ee8..9c110ea598e 100644 --- a/app/lib/admin/metrics/measure/instance_accounts_measure.rb +++ b/app/lib/admin/metrics/measure/instance_accounts_measure.rb @@ -35,11 +35,8 @@ class Admin::Metrics::Measure::InstanceAccountsMeasure < Admin::Metrics::Measure Account .select(:id) .where(account_domain_sql(params[:include_subdomains])) - .where( - <<~SQL.squish - DATE_TRUNC('day', accounts.created_at)::date = axis.period - SQL - ).to_sql + .where(daily_period(:accounts)) + .to_sql end def params diff --git a/app/lib/admin/metrics/measure/instance_followers_measure.rb b/app/lib/admin/metrics/measure/instance_followers_measure.rb index 9cbd8a2392b..0681f3d2cf7 100644 --- a/app/lib/admin/metrics/measure/instance_followers_measure.rb +++ b/app/lib/admin/metrics/measure/instance_followers_measure.rb @@ -36,11 +36,8 @@ class Admin::Metrics::Measure::InstanceFollowersMeasure < Admin::Metrics::Measur .select(:id) .joins(:account) .where(account_domain_sql(params[:include_subdomains])) - .where( - <<~SQL.squish - DATE_TRUNC('day', follows.created_at)::date = axis.period - SQL - ).to_sql + .where(daily_period(:follows)) + .to_sql end def params diff --git a/app/lib/admin/metrics/measure/instance_follows_measure.rb b/app/lib/admin/metrics/measure/instance_follows_measure.rb index c219b8354fe..e2fbb200f97 100644 --- a/app/lib/admin/metrics/measure/instance_follows_measure.rb +++ b/app/lib/admin/metrics/measure/instance_follows_measure.rb @@ -36,11 +36,8 @@ class Admin::Metrics::Measure::InstanceFollowsMeasure < Admin::Metrics::Measure: .select(:id) .joins(:target_account) .where(account_domain_sql(params[:include_subdomains])) - .where( - <<~SQL.squish - DATE_TRUNC('day', follows.created_at)::date = axis.period - SQL - ).to_sql + .where(daily_period(:follows)) + .to_sql end def params diff --git a/app/lib/admin/metrics/measure/instance_media_attachments_measure.rb b/app/lib/admin/metrics/measure/instance_media_attachments_measure.rb index c6abb9a0006..b0aa81f52e3 100644 --- a/app/lib/admin/metrics/measure/instance_media_attachments_measure.rb +++ b/app/lib/admin/metrics/measure/instance_media_attachments_measure.rb @@ -45,11 +45,8 @@ class Admin::Metrics::Measure::InstanceMediaAttachmentsMeasure < Admin::Metrics: .select('COALESCE(media_attachments.file_file_size, 0) + COALESCE(media_attachments.thumbnail_file_size, 0) AS size') .joins(:account) .where(account_domain_sql(params[:include_subdomains])) - .where( - <<~SQL.squish - DATE_TRUNC('day', media_attachments.created_at)::date = axis.period - SQL - ).to_sql + .where(daily_period(:media_attachments)) + .to_sql end def select_target diff --git a/app/lib/admin/metrics/measure/instance_reports_measure.rb b/app/lib/admin/metrics/measure/instance_reports_measure.rb index 519a50b6f77..2be5a6e7842 100644 --- a/app/lib/admin/metrics/measure/instance_reports_measure.rb +++ b/app/lib/admin/metrics/measure/instance_reports_measure.rb @@ -36,11 +36,8 @@ class Admin::Metrics::Measure::InstanceReportsMeasure < Admin::Metrics::Measure: .select(:id) .joins(:target_account) .where(account_domain_sql(params[:include_subdomains])) - .where( - <<~SQL.squish - DATE_TRUNC('day', reports.created_at)::date = axis.period - SQL - ).to_sql + .where(daily_period(:reports)) + .to_sql end def params diff --git a/app/lib/admin/metrics/measure/instance_statuses_measure.rb b/app/lib/admin/metrics/measure/instance_statuses_measure.rb index 73dea4d5c48..e27da646c41 100644 --- a/app/lib/admin/metrics/measure/instance_statuses_measure.rb +++ b/app/lib/admin/metrics/measure/instance_statuses_measure.rb @@ -41,11 +41,8 @@ class Admin::Metrics::Measure::InstanceStatusesMeasure < Admin::Metrics::Measure statuses.id BETWEEN :earliest_status_id AND :latest_status_id SQL ) - .where( - <<~SQL.squish - date_trunc('day', statuses.created_at)::date = axis.period - SQL - ).to_sql + .where(daily_period(:statuses)) + .to_sql end def earliest_status_id diff --git a/app/lib/admin/metrics/measure/new_users_measure.rb b/app/lib/admin/metrics/measure/new_users_measure.rb index 66334cd11c8..f4a7e5b2931 100644 --- a/app/lib/admin/metrics/measure/new_users_measure.rb +++ b/app/lib/admin/metrics/measure/new_users_measure.rb @@ -24,10 +24,7 @@ class Admin::Metrics::Measure::NewUsersMeasure < Admin::Metrics::Measure::BaseMe def data_source_query User .select(:id) - .where( - <<~SQL.squish - DATE_TRUNC('day', users.created_at)::date = axis.period - SQL - ).to_sql + .where(daily_period(:users)) + .to_sql end end diff --git a/app/lib/admin/metrics/measure/query_helper.rb b/app/lib/admin/metrics/measure/query_helper.rb index 4145f3fa442..120c05f1bbc 100644 --- a/app/lib/admin/metrics/measure/query_helper.rb +++ b/app/lib/admin/metrics/measure/query_helper.rb @@ -33,6 +33,12 @@ module Admin::Metrics::Measure::QueryHelper SQL end + def daily_period(table, column = :created_at) + <<~SQL.squish + DATE_TRUNC('day', #{table}.#{column})::date = axis.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))" diff --git a/app/lib/admin/metrics/measure/resolved_reports_measure.rb b/app/lib/admin/metrics/measure/resolved_reports_measure.rb index 5c7b1c320fd..a3b67ebc595 100644 --- a/app/lib/admin/metrics/measure/resolved_reports_measure.rb +++ b/app/lib/admin/metrics/measure/resolved_reports_measure.rb @@ -24,10 +24,7 @@ class Admin::Metrics::Measure::ResolvedReportsMeasure < Admin::Metrics::Measure: def data_source_query Report .select(:id) - .where( - <<~SQL.squish - DATE_TRUNC('day', reports.action_taken_at)::date = axis.period - SQL - ).to_sql + .where(daily_period(:reports, :action_taken_at)) + .to_sql end end diff --git a/app/lib/admin/metrics/measure/tag_servers_measure.rb b/app/lib/admin/metrics/measure/tag_servers_measure.rb index 5eca9813d5a..dfde12c8180 100644 --- a/app/lib/admin/metrics/measure/tag_servers_measure.rb +++ b/app/lib/admin/metrics/measure/tag_servers_measure.rb @@ -37,11 +37,8 @@ class Admin::Metrics::Measure::TagServersMeasure < Admin::Metrics::Measure::Base AND statuses.id BETWEEN :earliest_status_id AND :latest_status_id SQL ) - .where( - <<~SQL.squish - date_trunc('day', statuses.created_at)::date = axis.period - SQL - ).to_sql + .where(daily_period(:statuses)) + .to_sql end def earliest_status_id From 87796e6680ba2a8c248a445e872ac6d16be561e6 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Tue, 11 Jun 2024 10:22:25 -0400 Subject: [PATCH 05/17] Method for date trunc compare --- app/lib/admin/metrics/measure/opened_reports_measure.rb | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/app/lib/admin/metrics/measure/opened_reports_measure.rb b/app/lib/admin/metrics/measure/opened_reports_measure.rb index 9628dd5c7da..31ce99205ac 100644 --- a/app/lib/admin/metrics/measure/opened_reports_measure.rb +++ b/app/lib/admin/metrics/measure/opened_reports_measure.rb @@ -24,10 +24,7 @@ class Admin::Metrics::Measure::OpenedReportsMeasure < Admin::Metrics::Measure::B def data_source_query Report .select(:id) - .where( - <<~SQL.squish - DATE_TRUNC('day', reports.created_at)::date = axis.period - SQL - ).to_sql + .where(daily_period(:reports)) + .to_sql end end From 32849942a19368eb8af5fe2e7101daef604ea340 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Tue, 11 Jun 2024 10:24:39 -0400 Subject: [PATCH 06/17] Move to_sql to query helper --- app/lib/admin/metrics/measure/instance_accounts_measure.rb | 1 - app/lib/admin/metrics/measure/instance_followers_measure.rb | 1 - app/lib/admin/metrics/measure/instance_follows_measure.rb | 1 - .../admin/metrics/measure/instance_media_attachments_measure.rb | 1 - app/lib/admin/metrics/measure/instance_reports_measure.rb | 1 - app/lib/admin/metrics/measure/instance_statuses_measure.rb | 1 - app/lib/admin/metrics/measure/new_users_measure.rb | 1 - app/lib/admin/metrics/measure/opened_reports_measure.rb | 1 - app/lib/admin/metrics/measure/query_helper.rb | 2 +- app/lib/admin/metrics/measure/resolved_reports_measure.rb | 1 - app/lib/admin/metrics/measure/tag_servers_measure.rb | 1 - 11 files changed, 1 insertion(+), 11 deletions(-) diff --git a/app/lib/admin/metrics/measure/instance_accounts_measure.rb b/app/lib/admin/metrics/measure/instance_accounts_measure.rb index 9c110ea598e..92f14015c94 100644 --- a/app/lib/admin/metrics/measure/instance_accounts_measure.rb +++ b/app/lib/admin/metrics/measure/instance_accounts_measure.rb @@ -36,7 +36,6 @@ class Admin::Metrics::Measure::InstanceAccountsMeasure < Admin::Metrics::Measure .select(:id) .where(account_domain_sql(params[:include_subdomains])) .where(daily_period(:accounts)) - .to_sql end def params diff --git a/app/lib/admin/metrics/measure/instance_followers_measure.rb b/app/lib/admin/metrics/measure/instance_followers_measure.rb index 0681f3d2cf7..29e47da1c8b 100644 --- a/app/lib/admin/metrics/measure/instance_followers_measure.rb +++ b/app/lib/admin/metrics/measure/instance_followers_measure.rb @@ -37,7 +37,6 @@ class Admin::Metrics::Measure::InstanceFollowersMeasure < Admin::Metrics::Measur .joins(:account) .where(account_domain_sql(params[:include_subdomains])) .where(daily_period(:follows)) - .to_sql end def params diff --git a/app/lib/admin/metrics/measure/instance_follows_measure.rb b/app/lib/admin/metrics/measure/instance_follows_measure.rb index e2fbb200f97..a2d717ccb98 100644 --- a/app/lib/admin/metrics/measure/instance_follows_measure.rb +++ b/app/lib/admin/metrics/measure/instance_follows_measure.rb @@ -37,7 +37,6 @@ class Admin::Metrics::Measure::InstanceFollowsMeasure < Admin::Metrics::Measure: .joins(:target_account) .where(account_domain_sql(params[:include_subdomains])) .where(daily_period(:follows)) - .to_sql end def params diff --git a/app/lib/admin/metrics/measure/instance_media_attachments_measure.rb b/app/lib/admin/metrics/measure/instance_media_attachments_measure.rb index b0aa81f52e3..7eba483767a 100644 --- a/app/lib/admin/metrics/measure/instance_media_attachments_measure.rb +++ b/app/lib/admin/metrics/measure/instance_media_attachments_measure.rb @@ -46,7 +46,6 @@ class Admin::Metrics::Measure::InstanceMediaAttachmentsMeasure < Admin::Metrics: .joins(:account) .where(account_domain_sql(params[:include_subdomains])) .where(daily_period(:media_attachments)) - .to_sql end def select_target diff --git a/app/lib/admin/metrics/measure/instance_reports_measure.rb b/app/lib/admin/metrics/measure/instance_reports_measure.rb index 2be5a6e7842..e62dca5937d 100644 --- a/app/lib/admin/metrics/measure/instance_reports_measure.rb +++ b/app/lib/admin/metrics/measure/instance_reports_measure.rb @@ -37,7 +37,6 @@ class Admin::Metrics::Measure::InstanceReportsMeasure < Admin::Metrics::Measure: .joins(:target_account) .where(account_domain_sql(params[:include_subdomains])) .where(daily_period(:reports)) - .to_sql end def params diff --git a/app/lib/admin/metrics/measure/instance_statuses_measure.rb b/app/lib/admin/metrics/measure/instance_statuses_measure.rb index e27da646c41..88c1d9138a8 100644 --- a/app/lib/admin/metrics/measure/instance_statuses_measure.rb +++ b/app/lib/admin/metrics/measure/instance_statuses_measure.rb @@ -42,7 +42,6 @@ class Admin::Metrics::Measure::InstanceStatusesMeasure < Admin::Metrics::Measure SQL ) .where(daily_period(:statuses)) - .to_sql end def earliest_status_id diff --git a/app/lib/admin/metrics/measure/new_users_measure.rb b/app/lib/admin/metrics/measure/new_users_measure.rb index f4a7e5b2931..e23d07fa70d 100644 --- a/app/lib/admin/metrics/measure/new_users_measure.rb +++ b/app/lib/admin/metrics/measure/new_users_measure.rb @@ -25,6 +25,5 @@ class Admin::Metrics::Measure::NewUsersMeasure < Admin::Metrics::Measure::BaseMe User .select(:id) .where(daily_period(:users)) - .to_sql end end diff --git a/app/lib/admin/metrics/measure/opened_reports_measure.rb b/app/lib/admin/metrics/measure/opened_reports_measure.rb index 31ce99205ac..9ea3a125d18 100644 --- a/app/lib/admin/metrics/measure/opened_reports_measure.rb +++ b/app/lib/admin/metrics/measure/opened_reports_measure.rb @@ -25,6 +25,5 @@ class Admin::Metrics::Measure::OpenedReportsMeasure < Admin::Metrics::Measure::B Report .select(:id) .where(daily_period(:reports)) - .to_sql end end diff --git a/app/lib/admin/metrics/measure/query_helper.rb b/app/lib/admin/metrics/measure/query_helper.rb index 120c05f1bbc..90e78280ac7 100644 --- a/app/lib/admin/metrics/measure/query_helper.rb +++ b/app/lib/admin/metrics/measure/query_helper.rb @@ -18,7 +18,7 @@ module Admin::Metrics::Measure::QueryHelper def sql_query_string <<~SQL.squish SELECT axis.*, ( - WITH data_source AS (#{data_source_query}) + WITH data_source AS (#{data_source_query.to_sql}) SELECT #{select_target} FROM data_source ) AS value FROM ( diff --git a/app/lib/admin/metrics/measure/resolved_reports_measure.rb b/app/lib/admin/metrics/measure/resolved_reports_measure.rb index a3b67ebc595..27bf8c0833a 100644 --- a/app/lib/admin/metrics/measure/resolved_reports_measure.rb +++ b/app/lib/admin/metrics/measure/resolved_reports_measure.rb @@ -25,6 +25,5 @@ class Admin::Metrics::Measure::ResolvedReportsMeasure < Admin::Metrics::Measure: Report .select(:id) .where(daily_period(:reports, :action_taken_at)) - .to_sql end end diff --git a/app/lib/admin/metrics/measure/tag_servers_measure.rb b/app/lib/admin/metrics/measure/tag_servers_measure.rb index dfde12c8180..542b8a7d19f 100644 --- a/app/lib/admin/metrics/measure/tag_servers_measure.rb +++ b/app/lib/admin/metrics/measure/tag_servers_measure.rb @@ -38,7 +38,6 @@ class Admin::Metrics::Measure::TagServersMeasure < Admin::Metrics::Measure::Base SQL ) .where(daily_period(:statuses)) - .to_sql end def earliest_status_id From f019cbdadb76e93d73a9d3abfd97361b92e2656a Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Tue, 11 Jun 2024 11:11:30 -0400 Subject: [PATCH 07/17] Remove arg from account domain sql --- app/lib/admin/metrics/measure/instance_accounts_measure.rb | 2 +- app/lib/admin/metrics/measure/instance_followers_measure.rb | 2 +- app/lib/admin/metrics/measure/instance_follows_measure.rb | 2 +- .../metrics/measure/instance_media_attachments_measure.rb | 2 +- app/lib/admin/metrics/measure/instance_reports_measure.rb | 2 +- app/lib/admin/metrics/measure/instance_statuses_measure.rb | 2 +- app/lib/admin/metrics/measure/query_helper.rb | 4 ++-- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/app/lib/admin/metrics/measure/instance_accounts_measure.rb b/app/lib/admin/metrics/measure/instance_accounts_measure.rb index 92f14015c94..079df47df0f 100644 --- a/app/lib/admin/metrics/measure/instance_accounts_measure.rb +++ b/app/lib/admin/metrics/measure/instance_accounts_measure.rb @@ -34,7 +34,7 @@ class Admin::Metrics::Measure::InstanceAccountsMeasure < Admin::Metrics::Measure def data_source_query Account .select(:id) - .where(account_domain_sql(params[:include_subdomains])) + .where(account_domain_sql) .where(daily_period(:accounts)) end diff --git a/app/lib/admin/metrics/measure/instance_followers_measure.rb b/app/lib/admin/metrics/measure/instance_followers_measure.rb index 29e47da1c8b..ddc7a638d68 100644 --- a/app/lib/admin/metrics/measure/instance_followers_measure.rb +++ b/app/lib/admin/metrics/measure/instance_followers_measure.rb @@ -35,7 +35,7 @@ class Admin::Metrics::Measure::InstanceFollowersMeasure < Admin::Metrics::Measur Follow .select(:id) .joins(:account) - .where(account_domain_sql(params[:include_subdomains])) + .where(account_domain_sql) .where(daily_period(:follows)) end diff --git a/app/lib/admin/metrics/measure/instance_follows_measure.rb b/app/lib/admin/metrics/measure/instance_follows_measure.rb index a2d717ccb98..d331d6e7890 100644 --- a/app/lib/admin/metrics/measure/instance_follows_measure.rb +++ b/app/lib/admin/metrics/measure/instance_follows_measure.rb @@ -35,7 +35,7 @@ class Admin::Metrics::Measure::InstanceFollowsMeasure < Admin::Metrics::Measure: Follow .select(:id) .joins(:target_account) - .where(account_domain_sql(params[:include_subdomains])) + .where(account_domain_sql) .where(daily_period(:follows)) end diff --git a/app/lib/admin/metrics/measure/instance_media_attachments_measure.rb b/app/lib/admin/metrics/measure/instance_media_attachments_measure.rb index 7eba483767a..f45238730ae 100644 --- a/app/lib/admin/metrics/measure/instance_media_attachments_measure.rb +++ b/app/lib/admin/metrics/measure/instance_media_attachments_measure.rb @@ -44,7 +44,7 @@ class Admin::Metrics::Measure::InstanceMediaAttachmentsMeasure < Admin::Metrics: MediaAttachment .select('COALESCE(media_attachments.file_file_size, 0) + COALESCE(media_attachments.thumbnail_file_size, 0) AS size') .joins(:account) - .where(account_domain_sql(params[:include_subdomains])) + .where(account_domain_sql) .where(daily_period(:media_attachments)) end diff --git a/app/lib/admin/metrics/measure/instance_reports_measure.rb b/app/lib/admin/metrics/measure/instance_reports_measure.rb index e62dca5937d..bc54a16d871 100644 --- a/app/lib/admin/metrics/measure/instance_reports_measure.rb +++ b/app/lib/admin/metrics/measure/instance_reports_measure.rb @@ -35,7 +35,7 @@ class Admin::Metrics::Measure::InstanceReportsMeasure < Admin::Metrics::Measure: Report .select(:id) .joins(:target_account) - .where(account_domain_sql(params[:include_subdomains])) + .where(account_domain_sql) .where(daily_period(:reports)) end diff --git a/app/lib/admin/metrics/measure/instance_statuses_measure.rb b/app/lib/admin/metrics/measure/instance_statuses_measure.rb index 88c1d9138a8..d22b877aa16 100644 --- a/app/lib/admin/metrics/measure/instance_statuses_measure.rb +++ b/app/lib/admin/metrics/measure/instance_statuses_measure.rb @@ -35,7 +35,7 @@ class Admin::Metrics::Measure::InstanceStatusesMeasure < Admin::Metrics::Measure Status .select(:id) .joins(:account) - .where(account_domain_sql(params[:include_subdomains])) + .where(account_domain_sql) .where( <<~SQL.squish statuses.id BETWEEN :earliest_status_id AND :latest_status_id diff --git a/app/lib/admin/metrics/measure/query_helper.rb b/app/lib/admin/metrics/measure/query_helper.rb index 90e78280ac7..1165bcc0b45 100644 --- a/app/lib/admin/metrics/measure/query_helper.rb +++ b/app/lib/admin/metrics/measure/query_helper.rb @@ -39,8 +39,8 @@ module Admin::Metrics::Measure::QueryHelper SQL end - def account_domain_sql(include_subdomains) - if include_subdomains + def account_domain_sql + if params[:include_subdomains] "accounts.domain IN (SELECT domain FROM instances WHERE reverse('.' || domain) LIKE reverse('.' || :domain::text))" else 'accounts.domain = :domain::text' From 4273e780c74518e862d7d52d630a52541c3b56b4 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Tue, 11 Jun 2024 11:18:54 -0400 Subject: [PATCH 08/17] use sql wrap in query helper --- app/lib/admin/metrics/measure/query_helper.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/app/lib/admin/metrics/measure/query_helper.rb b/app/lib/admin/metrics/measure/query_helper.rb index 1165bcc0b45..879d25cea75 100644 --- a/app/lib/admin/metrics/measure/query_helper.rb +++ b/app/lib/admin/metrics/measure/query_helper.rb @@ -41,9 +41,13 @@ module Admin::Metrics::Measure::QueryHelper def account_domain_sql if params[:include_subdomains] - "accounts.domain IN (SELECT domain FROM instances WHERE reverse('.' || domain) LIKE reverse('.' || :domain::text))" + <<~SQL.squish + accounts.domain IN (SELECT domain FROM instances WHERE reverse('.' || domain) LIKE reverse('.' || :domain::text)) + SQL else - 'accounts.domain = :domain::text' + <<~SQL.squish + accounts.domain = :domain::text + SQL end end end From e0692262d1ba04d9e62dda0eb8c62b20c46f186c Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Tue, 11 Jun 2024 11:30:45 -0400 Subject: [PATCH 09/17] Move extra sql params to base class --- .../admin/metrics/measure/instance_accounts_measure.rb | 6 +----- .../admin/metrics/measure/instance_followers_measure.rb | 6 +----- app/lib/admin/metrics/measure/instance_follows_measure.rb | 6 +----- .../metrics/measure/instance_media_attachments_measure.rb | 6 +----- app/lib/admin/metrics/measure/instance_reports_measure.rb | 6 +----- .../admin/metrics/measure/instance_statuses_measure.rb | 6 +++--- app/lib/admin/metrics/measure/query_helper.rb | 8 ++++++++ app/lib/admin/metrics/measure/resolved_reports_measure.rb | 4 ---- app/lib/admin/metrics/measure/tag_servers_measure.rb | 4 ++-- 9 files changed, 18 insertions(+), 34 deletions(-) diff --git a/app/lib/admin/metrics/measure/instance_accounts_measure.rb b/app/lib/admin/metrics/measure/instance_accounts_measure.rb index 079df47df0f..fdd0958014e 100644 --- a/app/lib/admin/metrics/measure/instance_accounts_measure.rb +++ b/app/lib/admin/metrics/measure/instance_accounts_measure.rb @@ -27,14 +27,10 @@ class Admin::Metrics::Measure::InstanceAccountsMeasure < Admin::Metrics::Measure nil end - def sql_array - [sql_query_string, { start_at: @start_at, end_at: @end_at, domain: params[:domain] }] - end - def data_source_query Account .select(:id) - .where(account_domain_sql) + .where(account_domain_sql, domain: params[:domain]) .where(daily_period(:accounts)) end diff --git a/app/lib/admin/metrics/measure/instance_followers_measure.rb b/app/lib/admin/metrics/measure/instance_followers_measure.rb index ddc7a638d68..ae243b8f6f4 100644 --- a/app/lib/admin/metrics/measure/instance_followers_measure.rb +++ b/app/lib/admin/metrics/measure/instance_followers_measure.rb @@ -27,15 +27,11 @@ class Admin::Metrics::Measure::InstanceFollowersMeasure < Admin::Metrics::Measur nil end - def sql_array - [sql_query_string, { start_at: @start_at, end_at: @end_at, domain: params[:domain] }] - end - def data_source_query Follow .select(:id) .joins(:account) - .where(account_domain_sql) + .where(account_domain_sql, domain: params[:domain]) .where(daily_period(:follows)) end diff --git a/app/lib/admin/metrics/measure/instance_follows_measure.rb b/app/lib/admin/metrics/measure/instance_follows_measure.rb index d331d6e7890..2cc2e19c9eb 100644 --- a/app/lib/admin/metrics/measure/instance_follows_measure.rb +++ b/app/lib/admin/metrics/measure/instance_follows_measure.rb @@ -27,15 +27,11 @@ class Admin::Metrics::Measure::InstanceFollowsMeasure < Admin::Metrics::Measure: nil end - def sql_array - [sql_query_string, { start_at: @start_at, end_at: @end_at, domain: params[:domain] }] - end - def data_source_query Follow .select(:id) .joins(:target_account) - .where(account_domain_sql) + .where(account_domain_sql, domain: params[:domain]) .where(daily_period(:follows)) end diff --git a/app/lib/admin/metrics/measure/instance_media_attachments_measure.rb b/app/lib/admin/metrics/measure/instance_media_attachments_measure.rb index f45238730ae..8b57fca8051 100644 --- a/app/lib/admin/metrics/measure/instance_media_attachments_measure.rb +++ b/app/lib/admin/metrics/measure/instance_media_attachments_measure.rb @@ -36,15 +36,11 @@ class Admin::Metrics::Measure::InstanceMediaAttachmentsMeasure < Admin::Metrics: nil end - def sql_array - [sql_query_string, { start_at: @start_at, end_at: @end_at, domain: params[:domain] }] - end - def data_source_query MediaAttachment .select('COALESCE(media_attachments.file_file_size, 0) + COALESCE(media_attachments.thumbnail_file_size, 0) AS size') .joins(:account) - .where(account_domain_sql) + .where(account_domain_sql, domain: params[:domain]) .where(daily_period(:media_attachments)) end diff --git a/app/lib/admin/metrics/measure/instance_reports_measure.rb b/app/lib/admin/metrics/measure/instance_reports_measure.rb index bc54a16d871..753e69b8f4c 100644 --- a/app/lib/admin/metrics/measure/instance_reports_measure.rb +++ b/app/lib/admin/metrics/measure/instance_reports_measure.rb @@ -27,15 +27,11 @@ class Admin::Metrics::Measure::InstanceReportsMeasure < Admin::Metrics::Measure: nil end - def sql_array - [sql_query_string, { start_at: @start_at, end_at: @end_at, domain: params[:domain] }] - end - def data_source_query Report .select(:id) .joins(:target_account) - .where(account_domain_sql) + .where(account_domain_sql, domain: params[:domain]) .where(daily_period(:reports)) end diff --git a/app/lib/admin/metrics/measure/instance_statuses_measure.rb b/app/lib/admin/metrics/measure/instance_statuses_measure.rb index d22b877aa16..2c0c3769d3e 100644 --- a/app/lib/admin/metrics/measure/instance_statuses_measure.rb +++ b/app/lib/admin/metrics/measure/instance_statuses_measure.rb @@ -27,15 +27,15 @@ class Admin::Metrics::Measure::InstanceStatusesMeasure < Admin::Metrics::Measure nil end - def sql_array - [sql_query_string, { start_at: @start_at, end_at: @end_at, domain: params[:domain], earliest_status_id: earliest_status_id, latest_status_id: latest_status_id }] + def extra_sql_params + { earliest_status_id: earliest_status_id, latest_status_id: latest_status_id } end def data_source_query Status .select(:id) .joins(:account) - .where(account_domain_sql) + .where(account_domain_sql, domain: params[:domain]) .where( <<~SQL.squish statuses.id BETWEEN :earliest_status_id AND :latest_status_id diff --git a/app/lib/admin/metrics/measure/query_helper.rb b/app/lib/admin/metrics/measure/query_helper.rb index 879d25cea75..83d0a6fc16b 100644 --- a/app/lib/admin/metrics/measure/query_helper.rb +++ b/app/lib/admin/metrics/measure/query_helper.rb @@ -15,6 +15,14 @@ module Admin::Metrics::Measure::QueryHelper ActiveRecord::Base.sanitize_sql_array(sql_array) end + def sql_array + [sql_query_string, { start_at: @start_at, end_at: @end_at }.merge(extra_sql_params)] + end + + def extra_sql_params + {} + end + def sql_query_string <<~SQL.squish SELECT axis.*, ( diff --git a/app/lib/admin/metrics/measure/resolved_reports_measure.rb b/app/lib/admin/metrics/measure/resolved_reports_measure.rb index 27bf8c0833a..5942dc7bcfb 100644 --- a/app/lib/admin/metrics/measure/resolved_reports_measure.rb +++ b/app/lib/admin/metrics/measure/resolved_reports_measure.rb @@ -17,10 +17,6 @@ class Admin::Metrics::Measure::ResolvedReportsMeasure < Admin::Metrics::Measure: Report.resolved.where(action_taken_at: previous_time_period).count end - def sql_array - [sql_query_string, { start_at: @start_at, end_at: @end_at }] - end - def data_source_query Report .select(:id) diff --git a/app/lib/admin/metrics/measure/tag_servers_measure.rb b/app/lib/admin/metrics/measure/tag_servers_measure.rb index 542b8a7d19f..1789c6c42fa 100644 --- a/app/lib/admin/metrics/measure/tag_servers_measure.rb +++ b/app/lib/admin/metrics/measure/tag_servers_measure.rb @@ -21,8 +21,8 @@ class Admin::Metrics::Measure::TagServersMeasure < Admin::Metrics::Measure::Base tag.statuses.where('statuses.id BETWEEN ? AND ?', Mastodon::Snowflake.id_at(@start_at - length_of_period, with_random: false), Mastodon::Snowflake.id_at(@end_at - length_of_period, with_random: false)).joins(:account).count('distinct accounts.domain') end - def sql_array - [sql_query_string, { start_at: @start_at, end_at: @end_at, tag_id: tag.id, earliest_status_id: earliest_status_id, latest_status_id: latest_status_id }] + def extra_sql_params + { tag_id: tag.id, earliest_status_id: earliest_status_id, latest_status_id: latest_status_id } end def data_source_query From 324e9673cbd5df2bed47ff9725f65120a0a803dd Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Tue, 11 Jun 2024 11:34:16 -0400 Subject: [PATCH 10/17] Remove extra sql args --- app/lib/admin/metrics/measure/instance_statuses_measure.rb | 6 +----- app/lib/admin/metrics/measure/query_helper.rb | 6 +----- app/lib/admin/metrics/measure/tag_servers_measure.rb | 6 +----- 3 files changed, 3 insertions(+), 15 deletions(-) diff --git a/app/lib/admin/metrics/measure/instance_statuses_measure.rb b/app/lib/admin/metrics/measure/instance_statuses_measure.rb index 2c0c3769d3e..b574b19c4d4 100644 --- a/app/lib/admin/metrics/measure/instance_statuses_measure.rb +++ b/app/lib/admin/metrics/measure/instance_statuses_measure.rb @@ -27,17 +27,13 @@ class Admin::Metrics::Measure::InstanceStatusesMeasure < Admin::Metrics::Measure nil end - def extra_sql_params - { earliest_status_id: earliest_status_id, latest_status_id: latest_status_id } - end - def data_source_query Status .select(:id) .joins(:account) .where(account_domain_sql, domain: params[:domain]) .where( - <<~SQL.squish + <<~SQL.squish, earliest_status_id: earliest_status_id, latest_status_id: latest_status_id statuses.id BETWEEN :earliest_status_id AND :latest_status_id SQL ) diff --git a/app/lib/admin/metrics/measure/query_helper.rb b/app/lib/admin/metrics/measure/query_helper.rb index 83d0a6fc16b..7c019ed2638 100644 --- a/app/lib/admin/metrics/measure/query_helper.rb +++ b/app/lib/admin/metrics/measure/query_helper.rb @@ -16,11 +16,7 @@ module Admin::Metrics::Measure::QueryHelper end def sql_array - [sql_query_string, { start_at: @start_at, end_at: @end_at }.merge(extra_sql_params)] - end - - def extra_sql_params - {} + [sql_query_string, { start_at: @start_at, end_at: @end_at }] end def sql_query_string diff --git a/app/lib/admin/metrics/measure/tag_servers_measure.rb b/app/lib/admin/metrics/measure/tag_servers_measure.rb index 1789c6c42fa..a76c67c7e35 100644 --- a/app/lib/admin/metrics/measure/tag_servers_measure.rb +++ b/app/lib/admin/metrics/measure/tag_servers_measure.rb @@ -21,10 +21,6 @@ class Admin::Metrics::Measure::TagServersMeasure < Admin::Metrics::Measure::Base tag.statuses.where('statuses.id BETWEEN ? AND ?', Mastodon::Snowflake.id_at(@start_at - length_of_period, with_random: false), Mastodon::Snowflake.id_at(@end_at - length_of_period, with_random: false)).joins(:account).count('distinct accounts.domain') end - def extra_sql_params - { tag_id: tag.id, earliest_status_id: earliest_status_id, latest_status_id: latest_status_id } - end - def data_source_query Status .select('accounts.domain') @@ -32,7 +28,7 @@ class Admin::Metrics::Measure::TagServersMeasure < Admin::Metrics::Measure::Base .reorder(nil) .joins(:tags, :account) .where( - <<~SQL.squish + <<~SQL.squish, tag_id: tag.id, earliest_status_id: earliest_status_id, latest_status_id: latest_status_id statuses_tags.tag_id = :tag_id AND statuses.id BETWEEN :earliest_status_id AND :latest_status_id SQL From abe946296b9ef096106acf9910206c5e00c59fe0 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Tue, 11 Jun 2024 11:37:24 -0400 Subject: [PATCH 11/17] wrap with sql --- .../metrics/measure/instance_media_attachments_measure.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/lib/admin/metrics/measure/instance_media_attachments_measure.rb b/app/lib/admin/metrics/measure/instance_media_attachments_measure.rb index 8b57fca8051..c089a752544 100644 --- a/app/lib/admin/metrics/measure/instance_media_attachments_measure.rb +++ b/app/lib/admin/metrics/measure/instance_media_attachments_measure.rb @@ -38,7 +38,11 @@ class Admin::Metrics::Measure::InstanceMediaAttachmentsMeasure < Admin::Metrics: def data_source_query MediaAttachment - .select('COALESCE(media_attachments.file_file_size, 0) + COALESCE(media_attachments.thumbnail_file_size, 0) AS size') + .select( + <<~SQL.squish + COALESCE(media_attachments.file_file_size, 0) + COALESCE(media_attachments.thumbnail_file_size, 0) AS size + SQL + ) .joins(:account) .where(account_domain_sql, domain: params[:domain]) .where(daily_period(:media_attachments)) From f3d9e6163936101200c4670822eccfe81be3e7c6 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Tue, 11 Jun 2024 11:38:42 -0400 Subject: [PATCH 12/17] Separate tags / betweens --- app/lib/admin/metrics/measure/tag_servers_measure.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/app/lib/admin/metrics/measure/tag_servers_measure.rb b/app/lib/admin/metrics/measure/tag_servers_measure.rb index a76c67c7e35..8d2fbf3739b 100644 --- a/app/lib/admin/metrics/measure/tag_servers_measure.rb +++ b/app/lib/admin/metrics/measure/tag_servers_measure.rb @@ -28,9 +28,13 @@ class Admin::Metrics::Measure::TagServersMeasure < Admin::Metrics::Measure::Base .reorder(nil) .joins(:tags, :account) .where( - <<~SQL.squish, tag_id: tag.id, earliest_status_id: earliest_status_id, latest_status_id: latest_status_id + <<~SQL.squish, tag_id: tag.id statuses_tags.tag_id = :tag_id - AND statuses.id BETWEEN :earliest_status_id AND :latest_status_id + SQL + ) + .where( + <<~SQL.squish, earliest_status_id: earliest_status_id, latest_status_id: latest_status_id + statuses.id BETWEEN :earliest_status_id AND :latest_status_id SQL ) .where(daily_period(:statuses)) From f87bbe6184571da069a9227c62bd33e81f37ef79 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Tue, 11 Jun 2024 11:40:52 -0400 Subject: [PATCH 13/17] Embroil it in controversery --- app/lib/admin/metrics/measure/tag_servers_measure.rb | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/app/lib/admin/metrics/measure/tag_servers_measure.rb b/app/lib/admin/metrics/measure/tag_servers_measure.rb index 8d2fbf3739b..089d1cba3b2 100644 --- a/app/lib/admin/metrics/measure/tag_servers_measure.rb +++ b/app/lib/admin/metrics/measure/tag_servers_measure.rb @@ -27,11 +27,7 @@ class Admin::Metrics::Measure::TagServersMeasure < Admin::Metrics::Measure::Base .distinct .reorder(nil) .joins(:tags, :account) - .where( - <<~SQL.squish, tag_id: tag.id - statuses_tags.tag_id = :tag_id - SQL - ) + .where(statuses_tags: { tag_id: tag.id }) .where( <<~SQL.squish, earliest_status_id: earliest_status_id, latest_status_id: latest_status_id statuses.id BETWEEN :earliest_status_id AND :latest_status_id From 84411d4c974cc0901fb7d901b3ed2122fe182cd4 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Tue, 11 Jun 2024 11:44:11 -0400 Subject: [PATCH 14/17] Embroil it in controversery --- app/lib/admin/metrics/measure/instance_statuses_measure.rb | 6 +----- app/lib/admin/metrics/measure/query_helper.rb | 6 ++++++ app/lib/admin/metrics/measure/tag_servers_measure.rb | 6 +----- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/app/lib/admin/metrics/measure/instance_statuses_measure.rb b/app/lib/admin/metrics/measure/instance_statuses_measure.rb index b574b19c4d4..bac11fc384a 100644 --- a/app/lib/admin/metrics/measure/instance_statuses_measure.rb +++ b/app/lib/admin/metrics/measure/instance_statuses_measure.rb @@ -32,11 +32,7 @@ class Admin::Metrics::Measure::InstanceStatusesMeasure < Admin::Metrics::Measure .select(:id) .joins(:account) .where(account_domain_sql, domain: params[:domain]) - .where( - <<~SQL.squish, earliest_status_id: earliest_status_id, latest_status_id: latest_status_id - statuses.id BETWEEN :earliest_status_id AND :latest_status_id - SQL - ) + .where(status_range_sql, earliest_status_id: earliest_status_id, latest_status_id: latest_status_id) .where(daily_period(:statuses)) end diff --git a/app/lib/admin/metrics/measure/query_helper.rb b/app/lib/admin/metrics/measure/query_helper.rb index 7c019ed2638..e6142c97f25 100644 --- a/app/lib/admin/metrics/measure/query_helper.rb +++ b/app/lib/admin/metrics/measure/query_helper.rb @@ -43,6 +43,12 @@ module Admin::Metrics::Measure::QueryHelper SQL end + def status_range_sql + <<~SQL.squish + statuses.id BETWEEN :earliest_status_id AND :latest_status_id + SQL + end + def account_domain_sql if params[:include_subdomains] <<~SQL.squish diff --git a/app/lib/admin/metrics/measure/tag_servers_measure.rb b/app/lib/admin/metrics/measure/tag_servers_measure.rb index 089d1cba3b2..bb35acc3593 100644 --- a/app/lib/admin/metrics/measure/tag_servers_measure.rb +++ b/app/lib/admin/metrics/measure/tag_servers_measure.rb @@ -28,11 +28,7 @@ class Admin::Metrics::Measure::TagServersMeasure < Admin::Metrics::Measure::Base .reorder(nil) .joins(:tags, :account) .where(statuses_tags: { tag_id: tag.id }) - .where( - <<~SQL.squish, earliest_status_id: earliest_status_id, latest_status_id: latest_status_id - statuses.id BETWEEN :earliest_status_id AND :latest_status_id - SQL - ) + .where(status_range_sql, earliest_status_id: earliest_status_id, latest_status_id: latest_status_id) .where(daily_period(:statuses)) end From b22a152d9db627a19601e27531eed9b661c3b25f Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Tue, 11 Jun 2024 12:02:50 -0400 Subject: [PATCH 15/17] Rename to data_source --- app/lib/admin/metrics/measure/instance_accounts_measure.rb | 2 +- app/lib/admin/metrics/measure/instance_followers_measure.rb | 2 +- app/lib/admin/metrics/measure/instance_follows_measure.rb | 2 +- .../admin/metrics/measure/instance_media_attachments_measure.rb | 2 +- app/lib/admin/metrics/measure/instance_reports_measure.rb | 2 +- app/lib/admin/metrics/measure/instance_statuses_measure.rb | 2 +- app/lib/admin/metrics/measure/new_users_measure.rb | 2 +- app/lib/admin/metrics/measure/opened_reports_measure.rb | 2 +- app/lib/admin/metrics/measure/query_helper.rb | 2 +- app/lib/admin/metrics/measure/resolved_reports_measure.rb | 2 +- app/lib/admin/metrics/measure/tag_servers_measure.rb | 2 +- 11 files changed, 11 insertions(+), 11 deletions(-) diff --git a/app/lib/admin/metrics/measure/instance_accounts_measure.rb b/app/lib/admin/metrics/measure/instance_accounts_measure.rb index fdd0958014e..04de2b9b1c0 100644 --- a/app/lib/admin/metrics/measure/instance_accounts_measure.rb +++ b/app/lib/admin/metrics/measure/instance_accounts_measure.rb @@ -27,7 +27,7 @@ class Admin::Metrics::Measure::InstanceAccountsMeasure < Admin::Metrics::Measure nil end - def data_source_query + def data_source Account .select(:id) .where(account_domain_sql, domain: params[:domain]) diff --git a/app/lib/admin/metrics/measure/instance_followers_measure.rb b/app/lib/admin/metrics/measure/instance_followers_measure.rb index ae243b8f6f4..726d6d8f037 100644 --- a/app/lib/admin/metrics/measure/instance_followers_measure.rb +++ b/app/lib/admin/metrics/measure/instance_followers_measure.rb @@ -27,7 +27,7 @@ class Admin::Metrics::Measure::InstanceFollowersMeasure < Admin::Metrics::Measur nil end - def data_source_query + def data_source Follow .select(:id) .joins(:account) diff --git a/app/lib/admin/metrics/measure/instance_follows_measure.rb b/app/lib/admin/metrics/measure/instance_follows_measure.rb index 2cc2e19c9eb..24e8a32945f 100644 --- a/app/lib/admin/metrics/measure/instance_follows_measure.rb +++ b/app/lib/admin/metrics/measure/instance_follows_measure.rb @@ -27,7 +27,7 @@ class Admin::Metrics::Measure::InstanceFollowsMeasure < Admin::Metrics::Measure: nil end - def data_source_query + def data_source Follow .select(:id) .joins(:target_account) diff --git a/app/lib/admin/metrics/measure/instance_media_attachments_measure.rb b/app/lib/admin/metrics/measure/instance_media_attachments_measure.rb index c089a752544..8fa5234b429 100644 --- a/app/lib/admin/metrics/measure/instance_media_attachments_measure.rb +++ b/app/lib/admin/metrics/measure/instance_media_attachments_measure.rb @@ -36,7 +36,7 @@ class Admin::Metrics::Measure::InstanceMediaAttachmentsMeasure < Admin::Metrics: nil end - def data_source_query + def data_source MediaAttachment .select( <<~SQL.squish diff --git a/app/lib/admin/metrics/measure/instance_reports_measure.rb b/app/lib/admin/metrics/measure/instance_reports_measure.rb index 753e69b8f4c..2b760c4e843 100644 --- a/app/lib/admin/metrics/measure/instance_reports_measure.rb +++ b/app/lib/admin/metrics/measure/instance_reports_measure.rb @@ -27,7 +27,7 @@ class Admin::Metrics::Measure::InstanceReportsMeasure < Admin::Metrics::Measure: nil end - def data_source_query + def data_source Report .select(:id) .joins(:target_account) diff --git a/app/lib/admin/metrics/measure/instance_statuses_measure.rb b/app/lib/admin/metrics/measure/instance_statuses_measure.rb index bac11fc384a..3a3304b97c3 100644 --- a/app/lib/admin/metrics/measure/instance_statuses_measure.rb +++ b/app/lib/admin/metrics/measure/instance_statuses_measure.rb @@ -27,7 +27,7 @@ class Admin::Metrics::Measure::InstanceStatusesMeasure < Admin::Metrics::Measure nil end - def data_source_query + def data_source Status .select(:id) .joins(:account) diff --git a/app/lib/admin/metrics/measure/new_users_measure.rb b/app/lib/admin/metrics/measure/new_users_measure.rb index e23d07fa70d..c8212b874d5 100644 --- a/app/lib/admin/metrics/measure/new_users_measure.rb +++ b/app/lib/admin/metrics/measure/new_users_measure.rb @@ -21,7 +21,7 @@ class Admin::Metrics::Measure::NewUsersMeasure < Admin::Metrics::Measure::BaseMe [sql_query_string, { start_at: @start_at, end_at: @end_at }] end - def data_source_query + def data_source User .select(:id) .where(daily_period(:users)) diff --git a/app/lib/admin/metrics/measure/opened_reports_measure.rb b/app/lib/admin/metrics/measure/opened_reports_measure.rb index 9ea3a125d18..53d6d88e4a9 100644 --- a/app/lib/admin/metrics/measure/opened_reports_measure.rb +++ b/app/lib/admin/metrics/measure/opened_reports_measure.rb @@ -21,7 +21,7 @@ class Admin::Metrics::Measure::OpenedReportsMeasure < Admin::Metrics::Measure::B [sql_query_string, { start_at: @start_at, end_at: @end_at }] end - def data_source_query + def data_source Report .select(:id) .where(daily_period(:reports)) diff --git a/app/lib/admin/metrics/measure/query_helper.rb b/app/lib/admin/metrics/measure/query_helper.rb index e6142c97f25..864673239dd 100644 --- a/app/lib/admin/metrics/measure/query_helper.rb +++ b/app/lib/admin/metrics/measure/query_helper.rb @@ -22,7 +22,7 @@ module Admin::Metrics::Measure::QueryHelper def sql_query_string <<~SQL.squish SELECT axis.*, ( - WITH data_source AS (#{data_source_query.to_sql}) + WITH data_source AS (#{data_source.to_sql}) SELECT #{select_target} FROM data_source ) AS value FROM ( diff --git a/app/lib/admin/metrics/measure/resolved_reports_measure.rb b/app/lib/admin/metrics/measure/resolved_reports_measure.rb index 5942dc7bcfb..d9d5c71f4b6 100644 --- a/app/lib/admin/metrics/measure/resolved_reports_measure.rb +++ b/app/lib/admin/metrics/measure/resolved_reports_measure.rb @@ -17,7 +17,7 @@ class Admin::Metrics::Measure::ResolvedReportsMeasure < Admin::Metrics::Measure: Report.resolved.where(action_taken_at: previous_time_period).count end - def data_source_query + def data_source Report .select(:id) .where(daily_period(:reports, :action_taken_at)) diff --git a/app/lib/admin/metrics/measure/tag_servers_measure.rb b/app/lib/admin/metrics/measure/tag_servers_measure.rb index bb35acc3593..6b4f56fdbb8 100644 --- a/app/lib/admin/metrics/measure/tag_servers_measure.rb +++ b/app/lib/admin/metrics/measure/tag_servers_measure.rb @@ -21,7 +21,7 @@ class Admin::Metrics::Measure::TagServersMeasure < Admin::Metrics::Measure::Base tag.statuses.where('statuses.id BETWEEN ? AND ?', Mastodon::Snowflake.id_at(@start_at - length_of_period, with_random: false), Mastodon::Snowflake.id_at(@end_at - length_of_period, with_random: false)).joins(:account).count('distinct accounts.domain') end - def data_source_query + def data_source Status .select('accounts.domain') .distinct From 960acfca72eb9d7d275d5d52323d4934f3787ed0 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Tue, 11 Jun 2024 12:08:05 -0400 Subject: [PATCH 16/17] media size total --- .../measure/instance_media_attachments_measure.rb | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/app/lib/admin/metrics/measure/instance_media_attachments_measure.rb b/app/lib/admin/metrics/measure/instance_media_attachments_measure.rb index 8fa5234b429..1e1089f2173 100644 --- a/app/lib/admin/metrics/measure/instance_media_attachments_measure.rb +++ b/app/lib/admin/metrics/measure/instance_media_attachments_measure.rb @@ -38,11 +38,7 @@ class Admin::Metrics::Measure::InstanceMediaAttachmentsMeasure < Admin::Metrics: def data_source MediaAttachment - .select( - <<~SQL.squish - COALESCE(media_attachments.file_file_size, 0) + COALESCE(media_attachments.thumbnail_file_size, 0) AS size - SQL - ) + .select(media_size_total) .joins(:account) .where(account_domain_sql, domain: params[:domain]) .where(daily_period(:media_attachments)) @@ -54,6 +50,12 @@ class Admin::Metrics::Measure::InstanceMediaAttachmentsMeasure < Admin::Metrics: SQL end + def media_size_total + <<~SQL.squish + COALESCE(media_attachments.file_file_size, 0) + COALESCE(media_attachments.thumbnail_file_size, 0) AS size + SQL + end + def params @params.permit(:domain, :include_subdomains) end From 677a17dcefe389176ad9077d08271fb4a4b0a06a Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Wed, 19 Jun 2024 07:02:25 -0400 Subject: [PATCH 17/17] Remove two more sql_array from report classes --- app/lib/admin/metrics/measure/new_users_measure.rb | 4 ---- app/lib/admin/metrics/measure/opened_reports_measure.rb | 4 ---- 2 files changed, 8 deletions(-) diff --git a/app/lib/admin/metrics/measure/new_users_measure.rb b/app/lib/admin/metrics/measure/new_users_measure.rb index c8212b874d5..d70f86086ee 100644 --- a/app/lib/admin/metrics/measure/new_users_measure.rb +++ b/app/lib/admin/metrics/measure/new_users_measure.rb @@ -17,10 +17,6 @@ class Admin::Metrics::Measure::NewUsersMeasure < Admin::Metrics::Measure::BaseMe User.where(created_at: previous_time_period).count end - def sql_array - [sql_query_string, { start_at: @start_at, end_at: @end_at }] - end - def data_source User .select(:id) diff --git a/app/lib/admin/metrics/measure/opened_reports_measure.rb b/app/lib/admin/metrics/measure/opened_reports_measure.rb index 53d6d88e4a9..8d901dfd169 100644 --- a/app/lib/admin/metrics/measure/opened_reports_measure.rb +++ b/app/lib/admin/metrics/measure/opened_reports_measure.rb @@ -17,10 +17,6 @@ class Admin::Metrics::Measure::OpenedReportsMeasure < Admin::Metrics::Measure::B Report.where(created_at: previous_time_period).count end - def sql_array - [sql_query_string, { start_at: @start_at, end_at: @end_at }] - end - def data_source Report .select(:id)