Class: RailsPulse::Dashboard::Tables::SlowRoutes
- Inherits:
-
Object
- Object
- RailsPulse::Dashboard::Tables::SlowRoutes
- Includes:
- FormattingHelper
- Defined in:
- app/models/rails_pulse/dashboard/tables/slow_routes.rb
Instance Method Summary collapse
-
#initialize(disabled_tags: [], show_non_tagged: true) ⇒ SlowRoutes
constructor
A new instance of SlowRoutes.
- #to_table_data ⇒ Object
Methods included from FormattingHelper
#human_readable_occurred_at, #human_readable_summary_period, #time_ago_in_words
Constructor Details
#initialize(disabled_tags: [], show_non_tagged: true) ⇒ SlowRoutes
Returns a new instance of SlowRoutes.
7 8 9 10 |
# File 'app/models/rails_pulse/dashboard/tables/slow_routes.rb', line 7 def initialize(disabled_tags: [], show_non_tagged: true) @disabled_tags = @show_non_tagged = show_non_tagged end |
Instance Method Details
#to_table_data ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'app/models/rails_pulse/dashboard/tables/slow_routes.rb', line 12 def to_table_data # Get data for this week this_week_start = 1.week.ago.beginning_of_week this_week_end = Time.current.end_of_week # Fetch route data from Summary records for this week route_data = RailsPulse::Summary .with_tag_filters(@disabled_tags, @show_non_tagged) .joins("INNER JOIN rails_pulse_routes ON rails_pulse_routes.id = rails_pulse_summaries.summarizable_id") .where( summarizable_type: "RailsPulse::Route", period_type: "day", period_start: this_week_start..this_week_end ) .group("rails_pulse_summaries.summarizable_id, rails_pulse_routes.path") .select( "rails_pulse_summaries.summarizable_id as route_id", "rails_pulse_routes.path", "SUM(rails_pulse_summaries.avg_duration * rails_pulse_summaries.count) / SUM(rails_pulse_summaries.count) as avg_duration", "SUM(rails_pulse_summaries.count) as request_count", "MAX(rails_pulse_summaries.period_end) as last_seen" ) .order("avg_duration DESC") .limit(5) # Build data rows data_rows = route_data.map do |record| { route_path: record.path, route_id: record.route_id, route_link: RailsPulse::Engine.routes.url_helpers.route_path(record.route_id), average_time: record.avg_duration.to_f.round(0), request_count: record.request_count, last_request: time_ago_in_words(record.last_seen) } end # Return new structure with columns and data { columns: [ { field: :route_path, label: "Route", link_to: :route_link, class: "w-auto" }, { field: :average_time, label: "Average Time", class: "w-32" }, { field: :request_count, label: "Requests", class: "w-24" }, { field: :last_request, label: "Last Request", class: "w-32" } ], data: data_rows } end |