mirror of
https://github.com/mastodon/mastodon.git
synced 2025-09-05 17:31:12 +00:00
Add MediaAttachment.combined_media_file_size
method (#35570)
This commit is contained in:
parent
8896d6c1b1
commit
3146109b08
|
@ -40,7 +40,7 @@ class Admin::Metrics::Dimension::SpaceUsageDimension < Admin::Metrics::Dimension
|
|||
|
||||
def media_size
|
||||
value = [
|
||||
MediaAttachment.sum(Arel.sql('COALESCE(file_file_size, 0) + COALESCE(thumbnail_file_size, 0)')),
|
||||
MediaAttachment.sum(MediaAttachment.combined_media_file_size),
|
||||
CustomEmoji.sum(:image_file_size),
|
||||
PreviewCard.sum(:image_file_size),
|
||||
Account.sum(Arel.sql('COALESCE(avatar_file_size, 0) + COALESCE(header_file_size, 0)')),
|
||||
|
|
|
@ -29,7 +29,7 @@ class Admin::Metrics::Measure::InstanceMediaAttachmentsMeasure < Admin::Metrics:
|
|||
def perform_total_query
|
||||
domain = params[:domain]
|
||||
domain = Instance.by_domain_and_subdomains(params[:domain]).select(:domain) if params[:include_subdomains]
|
||||
MediaAttachment.joins(:account).merge(Account.where(domain: domain)).sum('COALESCE(file_file_size, 0) + COALESCE(thumbnail_file_size, 0)')
|
||||
MediaAttachment.joins(:account).merge(Account.where(domain: domain)).sum(MediaAttachment.combined_media_file_size)
|
||||
end
|
||||
|
||||
def perform_previous_total_query
|
||||
|
@ -44,7 +44,7 @@ class Admin::Metrics::Measure::InstanceMediaAttachmentsMeasure < Admin::Metrics:
|
|||
<<~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
|
||||
SELECT #{media_size_total} 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
|
||||
|
@ -58,6 +58,10 @@ class Admin::Metrics::Measure::InstanceMediaAttachmentsMeasure < Admin::Metrics:
|
|||
SQL
|
||||
end
|
||||
|
||||
def media_size_total
|
||||
MediaAttachment.combined_media_file_size.to_sql
|
||||
end
|
||||
|
||||
def params
|
||||
@params.permit(:domain, :include_subdomains)
|
||||
end
|
||||
|
|
|
@ -298,6 +298,10 @@ class MediaAttachment < ApplicationRecord
|
|||
IMAGE_FILE_EXTENSIONS + VIDEO_FILE_EXTENSIONS + AUDIO_FILE_EXTENSIONS
|
||||
end
|
||||
|
||||
def combined_media_file_size
|
||||
arel_table.coalesce(arel_table[:file_file_size], 0) + arel_table.coalesce(arel_table[:thumbnail_file_size], 0)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def file_styles(attachment)
|
||||
|
|
|
@ -313,9 +313,7 @@ module Mastodon::CLI
|
|||
end
|
||||
|
||||
def combined_media_sum
|
||||
Arel.sql(<<~SQL.squish)
|
||||
COALESCE(file_file_size, 0) + COALESCE(thumbnail_file_size, 0)
|
||||
SQL
|
||||
MediaAttachment.combined_media_file_size
|
||||
end
|
||||
|
||||
def preload_records_from_mixed_objects(objects)
|
||||
|
|
|
@ -313,6 +313,12 @@ RSpec.describe MediaAttachment, :attachment_processing do
|
|||
end
|
||||
end
|
||||
|
||||
describe '.combined_media_file_size' do
|
||||
subject { described_class.combined_media_file_size }
|
||||
|
||||
it { is_expected.to be_an(Arel::Nodes::Grouping) }
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def media_metadata
|
||||
|
|
Loading…
Reference in New Issue
Block a user