mirror of
https://github.com/mastodon/mastodon.git
synced 2024-08-20 21:08:15 -07:00
Method for date trunc compare
This commit is contained in:
parent
c570eca393
commit
f1e35a60e6
10 changed files with 24 additions and 45 deletions
|
@ -35,11 +35,8 @@ class Admin::Metrics::Measure::InstanceAccountsMeasure < Admin::Metrics::Measure
|
||||||
Account
|
Account
|
||||||
.select(:id)
|
.select(:id)
|
||||||
.where(account_domain_sql(params[:include_subdomains]))
|
.where(account_domain_sql(params[:include_subdomains]))
|
||||||
.where(
|
.where(daily_period(:accounts))
|
||||||
<<~SQL.squish
|
.to_sql
|
||||||
DATE_TRUNC('day', accounts.created_at)::date = axis.period
|
|
||||||
SQL
|
|
||||||
).to_sql
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def params
|
def params
|
||||||
|
|
|
@ -36,11 +36,8 @@ class Admin::Metrics::Measure::InstanceFollowersMeasure < Admin::Metrics::Measur
|
||||||
.select(:id)
|
.select(:id)
|
||||||
.joins(:account)
|
.joins(:account)
|
||||||
.where(account_domain_sql(params[:include_subdomains]))
|
.where(account_domain_sql(params[:include_subdomains]))
|
||||||
.where(
|
.where(daily_period(:follows))
|
||||||
<<~SQL.squish
|
.to_sql
|
||||||
DATE_TRUNC('day', follows.created_at)::date = axis.period
|
|
||||||
SQL
|
|
||||||
).to_sql
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def params
|
def params
|
||||||
|
|
|
@ -36,11 +36,8 @@ class Admin::Metrics::Measure::InstanceFollowsMeasure < Admin::Metrics::Measure:
|
||||||
.select(:id)
|
.select(:id)
|
||||||
.joins(:target_account)
|
.joins(:target_account)
|
||||||
.where(account_domain_sql(params[:include_subdomains]))
|
.where(account_domain_sql(params[:include_subdomains]))
|
||||||
.where(
|
.where(daily_period(:follows))
|
||||||
<<~SQL.squish
|
.to_sql
|
||||||
DATE_TRUNC('day', follows.created_at)::date = axis.period
|
|
||||||
SQL
|
|
||||||
).to_sql
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def params
|
def params
|
||||||
|
|
|
@ -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')
|
.select('COALESCE(media_attachments.file_file_size, 0) + COALESCE(media_attachments.thumbnail_file_size, 0) AS size')
|
||||||
.joins(:account)
|
.joins(:account)
|
||||||
.where(account_domain_sql(params[:include_subdomains]))
|
.where(account_domain_sql(params[:include_subdomains]))
|
||||||
.where(
|
.where(daily_period(:media_attachments))
|
||||||
<<~SQL.squish
|
.to_sql
|
||||||
DATE_TRUNC('day', media_attachments.created_at)::date = axis.period
|
|
||||||
SQL
|
|
||||||
).to_sql
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def select_target
|
def select_target
|
||||||
|
|
|
@ -36,11 +36,8 @@ class Admin::Metrics::Measure::InstanceReportsMeasure < Admin::Metrics::Measure:
|
||||||
.select(:id)
|
.select(:id)
|
||||||
.joins(:target_account)
|
.joins(:target_account)
|
||||||
.where(account_domain_sql(params[:include_subdomains]))
|
.where(account_domain_sql(params[:include_subdomains]))
|
||||||
.where(
|
.where(daily_period(:reports))
|
||||||
<<~SQL.squish
|
.to_sql
|
||||||
DATE_TRUNC('day', reports.created_at)::date = axis.period
|
|
||||||
SQL
|
|
||||||
).to_sql
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def params
|
def params
|
||||||
|
|
|
@ -41,11 +41,8 @@ class Admin::Metrics::Measure::InstanceStatusesMeasure < Admin::Metrics::Measure
|
||||||
statuses.id BETWEEN :earliest_status_id AND :latest_status_id
|
statuses.id BETWEEN :earliest_status_id AND :latest_status_id
|
||||||
SQL
|
SQL
|
||||||
)
|
)
|
||||||
.where(
|
.where(daily_period(:statuses))
|
||||||
<<~SQL.squish
|
.to_sql
|
||||||
date_trunc('day', statuses.created_at)::date = axis.period
|
|
||||||
SQL
|
|
||||||
).to_sql
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def earliest_status_id
|
def earliest_status_id
|
||||||
|
|
|
@ -24,10 +24,7 @@ class Admin::Metrics::Measure::NewUsersMeasure < Admin::Metrics::Measure::BaseMe
|
||||||
def data_source_query
|
def data_source_query
|
||||||
User
|
User
|
||||||
.select(:id)
|
.select(:id)
|
||||||
.where(
|
.where(daily_period(:users))
|
||||||
<<~SQL.squish
|
.to_sql
|
||||||
DATE_TRUNC('day', users.created_at)::date = axis.period
|
|
||||||
SQL
|
|
||||||
).to_sql
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -33,6 +33,12 @@ module Admin::Metrics::Measure::QueryHelper
|
||||||
SQL
|
SQL
|
||||||
end
|
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)
|
def account_domain_sql(include_subdomains)
|
||||||
if include_subdomains
|
if include_subdomains
|
||||||
"accounts.domain IN (SELECT domain FROM instances WHERE reverse('.' || domain) LIKE reverse('.' || :domain::text))"
|
"accounts.domain IN (SELECT domain FROM instances WHERE reverse('.' || domain) LIKE reverse('.' || :domain::text))"
|
||||||
|
|
|
@ -24,10 +24,7 @@ class Admin::Metrics::Measure::ResolvedReportsMeasure < Admin::Metrics::Measure:
|
||||||
def data_source_query
|
def data_source_query
|
||||||
Report
|
Report
|
||||||
.select(:id)
|
.select(:id)
|
||||||
.where(
|
.where(daily_period(:reports, :action_taken_at))
|
||||||
<<~SQL.squish
|
.to_sql
|
||||||
DATE_TRUNC('day', reports.action_taken_at)::date = axis.period
|
|
||||||
SQL
|
|
||||||
).to_sql
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -37,11 +37,8 @@ class Admin::Metrics::Measure::TagServersMeasure < Admin::Metrics::Measure::Base
|
||||||
AND statuses.id BETWEEN :earliest_status_id AND :latest_status_id
|
AND statuses.id BETWEEN :earliest_status_id AND :latest_status_id
|
||||||
SQL
|
SQL
|
||||||
)
|
)
|
||||||
.where(
|
.where(daily_period(:statuses))
|
||||||
<<~SQL.squish
|
.to_sql
|
||||||
date_trunc('day', statuses.created_at)::date = axis.period
|
|
||||||
SQL
|
|
||||||
).to_sql
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def earliest_status_id
|
def earliest_status_id
|
||||||
|
|
Loading…
Reference in a new issue