Method for date trunc compare

pull/30654/head
Matt Jankowski 2024-06-11 10:20:38 -04:00
parent bc61079155
commit bde4635490
10 changed files with 24 additions and 45 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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))"

View File

@ -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

View File

@ -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