mirror of
https://github.com/mastodon/mastodon.git
synced 2024-08-20 21:08:15 -07:00
Use AR to build
This commit is contained in:
parent
13888d827c
commit
c570eca393
2 changed files with 25 additions and 16 deletions
|
@ -41,13 +41,15 @@ class Admin::Metrics::Measure::InstanceMediaAttachmentsMeasure < Admin::Metrics:
|
|||
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(params[:include_subdomains]))
|
||||
.where(
|
||||
<<~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])}
|
||||
DATE_TRUNC('day', media_attachments.created_at)::date = axis.period
|
||||
SQL
|
||||
).to_sql
|
||||
end
|
||||
|
||||
def select_target
|
||||
|
|
|
@ -26,15 +26,22 @@ class Admin::Metrics::Measure::TagServersMeasure < Admin::Metrics::Measure::Base
|
|||
end
|
||||
|
||||
def data_source_query
|
||||
Status
|
||||
.select('accounts.domain')
|
||||
.distinct
|
||||
.reorder(nil)
|
||||
.joins(:tags, :account)
|
||||
.where(
|
||||
<<~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
|
||||
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
|
||||
)
|
||||
.where(
|
||||
<<~SQL.squish
|
||||
date_trunc('day', statuses.created_at)::date = axis.period
|
||||
SQL
|
||||
).to_sql
|
||||
end
|
||||
|
||||
def earliest_status_id
|
||||
|
|
Loading…
Reference in a new issue