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