1
0
Fork 0
mirror of https://github.com/mastodon/mastodon.git synced 2024-08-20 21:08:15 -07:00

First pass at interface improvement

This commit is contained in:
Matt Jankowski 2024-04-19 11:58:55 -04:00
parent a609940ec9
commit e2a243ae31
11 changed files with 105 additions and 153 deletions

View file

@ -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] }] [sql_query_string, { start_at: @start_at, end_at: @end_at, domain: params[:domain] }]
end end
def sql_query_string def data_source_query
Account
.select(:id)
.where(
<<~SQL.squish <<~SQL.squish
SELECT axis.*, ( DATE_TRUNC('day', accounts.created_at)::date = axis.period
WITH new_accounts AS (
SELECT accounts.id
FROM accounts
WHERE date_trunc('day', accounts.created_at)::date = axis.period
AND #{account_domain_sql(params[:include_subdomains])} 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 end
def params def params

View file

@ -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] }] [sql_query_string, { start_at: @start_at, end_at: @end_at, domain: params[:domain] }]
end end
def sql_query_string def data_source_query
Follow
.select(:id)
.joins(:account)
.where(
<<~SQL.squish <<~SQL.squish
SELECT axis.*, ( DATE_TRUNC('day', follows.created_at)::date = axis.period
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
AND #{account_domain_sql(params[:include_subdomains])} 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 end
def params def params

View file

@ -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] }] [sql_query_string, { start_at: @start_at, end_at: @end_at, domain: params[:domain] }]
end end
def sql_query_string def data_source_query
Follow
.select(:id)
.joins(:target_account)
.where(
<<~SQL.squish <<~SQL.squish
SELECT axis.*, ( DATE_TRUNC('day', follows.created_at)::date = axis.period
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
AND #{account_domain_sql(params[:include_subdomains])} 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 end
def params def params

View file

@ -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] }] [sql_query_string, { start_at: @start_at, end_at: @end_at, domain: params[:domain] }]
end end
def sql_query_string def data_source_query
<<~SQL.squish <<~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 COALESCE(media_attachments.file_file_size, 0) + COALESCE(media_attachments.thumbnail_file_size, 0) AS size
FROM media_attachments FROM media_attachments
INNER JOIN accounts ON accounts.id = media_attachments.account_id INNER JOIN accounts ON accounts.id = media_attachments.account_id
WHERE date_trunc('day', media_attachments.created_at)::date = axis.period WHERE date_trunc('day', media_attachments.created_at)::date = axis.period
AND #{account_domain_sql(params[:include_subdomains])} AND #{account_domain_sql(params[:include_subdomains])}
) SQL
SELECT COALESCE(SUM(size), 0) FROM new_media_attachments end
) AS value
FROM ( def select_target
#{generated_series_days} <<~SQL.squish
) AS axis COALESCE(SUM(size), 0)
SQL SQL
end end

View file

@ -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] }] [sql_query_string, { start_at: @start_at, end_at: @end_at, domain: params[:domain] }]
end end
def sql_query_string def data_source_query
Report
.select(:id)
.joins(:target_account)
.where(
<<~SQL.squish <<~SQL.squish
SELECT axis.*, ( DATE_TRUNC('day', reports.created_at)::date = axis.period
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
AND #{account_domain_sql(params[:include_subdomains])} 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 end
def params def params

View file

@ -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 }] [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 end
def sql_query_string def data_source_query
Status
.select(:id)
.joins(:account)
.where(
<<~SQL.squish <<~SQL.squish
SELECT axis.*, ( statuses.id BETWEEN :earliest_status_id AND :latest_status_id
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 #{account_domain_sql(params[:include_subdomains])}
AND date_trunc('day', statuses.created_at)::date = axis.period AND date_trunc('day', statuses.created_at)::date = axis.period
)
SELECT count(*) FROM new_statuses
) AS value
FROM (
#{generated_series_days}
) AS axis
SQL SQL
).to_sql
end end
def earliest_status_id def earliest_status_id

View file

@ -21,19 +21,13 @@ class Admin::Metrics::Measure::NewUsersMeasure < Admin::Metrics::Measure::BaseMe
[sql_query_string, { start_at: @start_at, end_at: @end_at }] [sql_query_string, { start_at: @start_at, end_at: @end_at }]
end end
def sql_query_string def data_source_query
User
.select(:id)
.where(
<<~SQL.squish <<~SQL.squish
SELECT axis.*, ( DATE_TRUNC('day', users.created_at)::date = axis.period
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 SQL
).to_sql
end end
end end

View file

@ -21,19 +21,13 @@ class Admin::Metrics::Measure::OpenedReportsMeasure < Admin::Metrics::Measure::B
[sql_query_string, { start_at: @start_at, end_at: @end_at }] [sql_query_string, { start_at: @start_at, end_at: @end_at }]
end end
def sql_query_string def data_source_query
Report
.select(:id)
.where(
<<~SQL.squish <<~SQL.squish
SELECT axis.*, ( DATE_TRUNC('day', reports.created_at)::date = axis.period
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 SQL
).to_sql
end end
end end

View file

@ -15,12 +15,22 @@ module Admin::Metrics::Measure::QueryHelper
ActiveRecord::Base.sanitize_sql_array(sql_array) ActiveRecord::Base.sanitize_sql_array(sql_array)
end end
def generated_series_days def sql_query_string
Arel.sql(
<<~SQL.squish <<~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 SELECT generate_series(:start_at::timestamp, :end_at::timestamp, '1 day')::date AS period
) AS axis
SQL
end
def select_target
<<~SQL.squish
COUNT(*)
SQL SQL
)
end end
def account_domain_sql(include_subdomains) def account_domain_sql(include_subdomains)

View file

@ -21,19 +21,13 @@ class Admin::Metrics::Measure::ResolvedReportsMeasure < Admin::Metrics::Measure:
[sql_query_string, { start_at: @start_at, end_at: @end_at }] [sql_query_string, { start_at: @start_at, end_at: @end_at }]
end end
def sql_query_string def data_source_query
Report
.select(:id)
.where(
<<~SQL.squish <<~SQL.squish
SELECT axis.*, ( DATE_TRUNC('day', reports.action_taken_at)::date = axis.period
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 SQL
).to_sql
end end
end end

View file

@ -25,10 +25,8 @@ 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 }] [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 end
def sql_query_string def data_source_query
<<~SQL.squish <<~SQL.squish
SELECT axis.*, (
WITH tag_servers AS (
SELECT DISTINCT accounts.domain SELECT DISTINCT accounts.domain
FROM statuses FROM statuses
INNER JOIN statuses_tags ON statuses.id = statuses_tags.status_id INNER JOIN statuses_tags ON statuses.id = statuses_tags.status_id
@ -36,12 +34,6 @@ class Admin::Metrics::Measure::TagServersMeasure < Admin::Metrics::Measure::Base
WHERE statuses_tags.tag_id = :tag_id WHERE statuses_tags.tag_id = :tag_id
AND statuses.id BETWEEN :earliest_status_id AND :latest_status_id AND statuses.id BETWEEN :earliest_status_id AND :latest_status_id
AND date_trunc('day', statuses.created_at)::date = axis.period AND date_trunc('day', statuses.created_at)::date = axis.period
)
SELECT COUNT(*) FROM tag_servers
) AS value
FROM (
#{generated_series_days}
) as axis
SQL SQL
end end