From a8b3d2e4e4e244f6dd44a2f9fe971279511534ac Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Wed, 19 Jun 2024 04:45:47 -0400 Subject: [PATCH] Consolidate time periods methods into base measure (#30757) --- app/lib/admin/metrics/measure/active_users_measure.rb | 8 -------- app/lib/admin/metrics/measure/base_measure.rb | 4 ++-- .../admin/metrics/measure/instance_accounts_measure.rb | 8 -------- .../admin/metrics/measure/instance_followers_measure.rb | 8 -------- app/lib/admin/metrics/measure/instance_follows_measure.rb | 8 -------- .../metrics/measure/instance_media_attachments_measure.rb | 8 -------- app/lib/admin/metrics/measure/instance_reports_measure.rb | 8 -------- .../admin/metrics/measure/instance_statuses_measure.rb | 8 -------- app/lib/admin/metrics/measure/interactions_measure.rb | 8 -------- app/lib/admin/metrics/measure/tag_accounts_measure.rb | 8 -------- app/lib/admin/metrics/measure/tag_uses_measure.rb | 8 -------- 11 files changed, 2 insertions(+), 82 deletions(-) diff --git a/app/lib/admin/metrics/measure/active_users_measure.rb b/app/lib/admin/metrics/measure/active_users_measure.rb index e6f09d4bc..c085ced62 100644 --- a/app/lib/admin/metrics/measure/active_users_measure.rb +++ b/app/lib/admin/metrics/measure/active_users_measure.rb @@ -22,12 +22,4 @@ class Admin::Metrics::Measure::ActiveUsersMeasure < Admin::Metrics::Measure::Bas def activity_tracker @activity_tracker ||= ActivityTracker.new('activity:logins', :unique) end - - def time_period - (@start_at.to_date..@end_at.to_date) - end - - def previous_time_period - ((@start_at.to_date - length_of_period)..(@end_at.to_date - length_of_period)) - end end diff --git a/app/lib/admin/metrics/measure/base_measure.rb b/app/lib/admin/metrics/measure/base_measure.rb index e33a6c494..8b7fe39b5 100644 --- a/app/lib/admin/metrics/measure/base_measure.rb +++ b/app/lib/admin/metrics/measure/base_measure.rb @@ -86,11 +86,11 @@ class Admin::Metrics::Measure::BaseMeasure end def time_period - (@start_at..@end_at) + (@start_at.to_date..@end_at.to_date) end def previous_time_period - ((@start_at - length_of_period)..(@end_at - length_of_period)) + ((@start_at.to_date - length_of_period)..(@end_at.to_date - length_of_period)) end def length_of_period diff --git a/app/lib/admin/metrics/measure/instance_accounts_measure.rb b/app/lib/admin/metrics/measure/instance_accounts_measure.rb index 746780ee7..889a5e6f0 100644 --- a/app/lib/admin/metrics/measure/instance_accounts_measure.rb +++ b/app/lib/admin/metrics/measure/instance_accounts_measure.rb @@ -48,14 +48,6 @@ class Admin::Metrics::Measure::InstanceAccountsMeasure < Admin::Metrics::Measure SQL end - def time_period - (@start_at.to_date..@end_at.to_date) - end - - def previous_time_period - ((@start_at.to_date - length_of_period)..(@end_at.to_date - length_of_period)) - end - def params @params.permit(:domain, :include_subdomains) end diff --git a/app/lib/admin/metrics/measure/instance_followers_measure.rb b/app/lib/admin/metrics/measure/instance_followers_measure.rb index 0693d5a64..fa934c6b9 100644 --- a/app/lib/admin/metrics/measure/instance_followers_measure.rb +++ b/app/lib/admin/metrics/measure/instance_followers_measure.rb @@ -49,14 +49,6 @@ class Admin::Metrics::Measure::InstanceFollowersMeasure < Admin::Metrics::Measur SQL end - def time_period - (@start_at.to_date..@end_at.to_date) - end - - def previous_time_period - ((@start_at.to_date - length_of_period)..(@end_at.to_date - length_of_period)) - end - def params @params.permit(:domain, :include_subdomains) end diff --git a/app/lib/admin/metrics/measure/instance_follows_measure.rb b/app/lib/admin/metrics/measure/instance_follows_measure.rb index 90d381935..3f3ab73fc 100644 --- a/app/lib/admin/metrics/measure/instance_follows_measure.rb +++ b/app/lib/admin/metrics/measure/instance_follows_measure.rb @@ -49,14 +49,6 @@ class Admin::Metrics::Measure::InstanceFollowsMeasure < Admin::Metrics::Measure: SQL end - def time_period - (@start_at.to_date..@end_at.to_date) - end - - def previous_time_period - ((@start_at.to_date - length_of_period)..(@end_at.to_date - length_of_period)) - end - def params @params.permit(:domain, :include_subdomains) end diff --git a/app/lib/admin/metrics/measure/instance_media_attachments_measure.rb b/app/lib/admin/metrics/measure/instance_media_attachments_measure.rb index 89f8b4149..996ca52e0 100644 --- a/app/lib/admin/metrics/measure/instance_media_attachments_measure.rb +++ b/app/lib/admin/metrics/measure/instance_media_attachments_measure.rb @@ -58,14 +58,6 @@ class Admin::Metrics::Measure::InstanceMediaAttachmentsMeasure < Admin::Metrics: SQL end - def time_period - (@start_at.to_date..@end_at.to_date) - end - - def previous_time_period - ((@start_at.to_date - length_of_period)..(@end_at.to_date - length_of_period)) - end - def params @params.permit(:domain, :include_subdomains) end diff --git a/app/lib/admin/metrics/measure/instance_reports_measure.rb b/app/lib/admin/metrics/measure/instance_reports_measure.rb index 5f58387a6..ae1bb6e68 100644 --- a/app/lib/admin/metrics/measure/instance_reports_measure.rb +++ b/app/lib/admin/metrics/measure/instance_reports_measure.rb @@ -49,14 +49,6 @@ class Admin::Metrics::Measure::InstanceReportsMeasure < Admin::Metrics::Measure: SQL end - def time_period - (@start_at.to_date..@end_at.to_date) - end - - def previous_time_period - ((@start_at.to_date - length_of_period)..(@end_at.to_date - length_of_period)) - end - def params @params.permit(:domain, :include_subdomains) end diff --git a/app/lib/admin/metrics/measure/instance_statuses_measure.rb b/app/lib/admin/metrics/measure/instance_statuses_measure.rb index 5873c6e71..324d427b1 100644 --- a/app/lib/admin/metrics/measure/instance_statuses_measure.rb +++ b/app/lib/admin/metrics/measure/instance_statuses_measure.rb @@ -58,14 +58,6 @@ class Admin::Metrics::Measure::InstanceStatusesMeasure < Admin::Metrics::Measure Mastodon::Snowflake.id_at(@end_at.end_of_day, with_random: false) end - def time_period - (@start_at.to_date..@end_at.to_date) - end - - def previous_time_period - ((@start_at.to_date - length_of_period)..(@end_at.to_date - length_of_period)) - end - def params @params.permit(:domain, :include_subdomains) end diff --git a/app/lib/admin/metrics/measure/interactions_measure.rb b/app/lib/admin/metrics/measure/interactions_measure.rb index 7a2b7e0fa..f4b4836b4 100644 --- a/app/lib/admin/metrics/measure/interactions_measure.rb +++ b/app/lib/admin/metrics/measure/interactions_measure.rb @@ -22,12 +22,4 @@ class Admin::Metrics::Measure::InteractionsMeasure < Admin::Metrics::Measure::Ba def activity_tracker @activity_tracker ||= ActivityTracker.new('activity:interactions', :basic) end - - def time_period - (@start_at.to_date..@end_at.to_date) - end - - def previous_time_period - ((@start_at.to_date - length_of_period)..(@end_at.to_date - length_of_period)) - end end diff --git a/app/lib/admin/metrics/measure/tag_accounts_measure.rb b/app/lib/admin/metrics/measure/tag_accounts_measure.rb index 8f4512efe..906277b7d 100644 --- a/app/lib/admin/metrics/measure/tag_accounts_measure.rb +++ b/app/lib/admin/metrics/measure/tag_accounts_measure.rb @@ -27,14 +27,6 @@ class Admin::Metrics::Measure::TagAccountsMeasure < Admin::Metrics::Measure::Bas @tag ||= Tag.find(params[:id]) end - def time_period - (@start_at.to_date..@end_at.to_date) - end - - def previous_time_period - ((@start_at.to_date - length_of_period)..(@end_at.to_date - length_of_period)) - end - def params @params.permit(:id) end diff --git a/app/lib/admin/metrics/measure/tag_uses_measure.rb b/app/lib/admin/metrics/measure/tag_uses_measure.rb index bce86b89f..2be96a02b 100644 --- a/app/lib/admin/metrics/measure/tag_uses_measure.rb +++ b/app/lib/admin/metrics/measure/tag_uses_measure.rb @@ -27,14 +27,6 @@ class Admin::Metrics::Measure::TagUsesMeasure < Admin::Metrics::Measure::BaseMea @tag ||= Tag.find(params[:id]) end - def time_period - (@start_at.to_date..@end_at.to_date) - end - - def previous_time_period - ((@start_at.to_date - length_of_period)..(@end_at.to_date - length_of_period)) - end - def params @params.permit(:id) end