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
|
||||
.select(:id)
|
||||
.where(account_domain_sql(params[:include_subdomains]))
|
||||
.where(
|
||||
<<~SQL.squish
|
||||
DATE_TRUNC('day', accounts.created_at)::date = axis.period
|
||||
SQL
|
||||
).to_sql
|
||||
.where(daily_period(:accounts))
|
||||
.to_sql
|
||||
end
|
||||
|
||||
def params
|
||||
|
|
|
@ -36,11 +36,8 @@ class Admin::Metrics::Measure::InstanceFollowersMeasure < Admin::Metrics::Measur
|
|||
.select(:id)
|
||||
.joins(:account)
|
||||
.where(account_domain_sql(params[:include_subdomains]))
|
||||
.where(
|
||||
<<~SQL.squish
|
||||
DATE_TRUNC('day', follows.created_at)::date = axis.period
|
||||
SQL
|
||||
).to_sql
|
||||
.where(daily_period(:follows))
|
||||
.to_sql
|
||||
end
|
||||
|
||||
def params
|
||||
|
|
|
@ -36,11 +36,8 @@ class Admin::Metrics::Measure::InstanceFollowsMeasure < Admin::Metrics::Measure:
|
|||
.select(:id)
|
||||
.joins(:target_account)
|
||||
.where(account_domain_sql(params[:include_subdomains]))
|
||||
.where(
|
||||
<<~SQL.squish
|
||||
DATE_TRUNC('day', follows.created_at)::date = axis.period
|
||||
SQL
|
||||
).to_sql
|
||||
.where(daily_period(:follows))
|
||||
.to_sql
|
||||
end
|
||||
|
||||
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')
|
||||
.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
|
||||
.where(daily_period(:media_attachments))
|
||||
.to_sql
|
||||
end
|
||||
|
||||
def select_target
|
||||
|
|
|
@ -36,11 +36,8 @@ class Admin::Metrics::Measure::InstanceReportsMeasure < Admin::Metrics::Measure:
|
|||
.select(:id)
|
||||
.joins(:target_account)
|
||||
.where(account_domain_sql(params[:include_subdomains]))
|
||||
.where(
|
||||
<<~SQL.squish
|
||||
DATE_TRUNC('day', reports.created_at)::date = axis.period
|
||||
SQL
|
||||
).to_sql
|
||||
.where(daily_period(:reports))
|
||||
.to_sql
|
||||
end
|
||||
|
||||
def params
|
||||
|
|
|
@ -41,11 +41,8 @@ class Admin::Metrics::Measure::InstanceStatusesMeasure < Admin::Metrics::Measure
|
|||
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
|
||||
.where(daily_period(:statuses))
|
||||
.to_sql
|
||||
end
|
||||
|
||||
def earliest_status_id
|
||||
|
|
|
@ -24,10 +24,7 @@ class Admin::Metrics::Measure::NewUsersMeasure < Admin::Metrics::Measure::BaseMe
|
|||
def data_source_query
|
||||
User
|
||||
.select(:id)
|
||||
.where(
|
||||
<<~SQL.squish
|
||||
DATE_TRUNC('day', users.created_at)::date = axis.period
|
||||
SQL
|
||||
).to_sql
|
||||
.where(daily_period(:users))
|
||||
.to_sql
|
||||
end
|
||||
end
|
||||
|
|
|
@ -33,6 +33,12 @@ module Admin::Metrics::Measure::QueryHelper
|
|||
SQL
|
||||
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)
|
||||
if include_subdomains
|
||||
"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
|
||||
Report
|
||||
.select(:id)
|
||||
.where(
|
||||
<<~SQL.squish
|
||||
DATE_TRUNC('day', reports.action_taken_at)::date = axis.period
|
||||
SQL
|
||||
).to_sql
|
||||
.where(daily_period(:reports, :action_taken_at))
|
||||
.to_sql
|
||||
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
|
||||
SQL
|
||||
)
|
||||
.where(
|
||||
<<~SQL.squish
|
||||
date_trunc('day', statuses.created_at)::date = axis.period
|
||||
SQL
|
||||
).to_sql
|
||||
.where(daily_period(:statuses))
|
||||
.to_sql
|
||||
end
|
||||
|
||||
def earliest_status_id
|
||||
|
|
Loading…
Reference in a new issue