rails_pulse 0.1.2 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (83) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +10 -4
  3. data/app/assets/images/rails_pulse/dashboard.png +0 -0
  4. data/app/assets/images/rails_pulse/request.png +0 -0
  5. data/app/assets/stylesheets/rails_pulse/application.css +28 -5
  6. data/app/assets/stylesheets/rails_pulse/components/badge.css +13 -0
  7. data/app/assets/stylesheets/rails_pulse/components/base.css +12 -2
  8. data/app/assets/stylesheets/rails_pulse/components/collapsible.css +30 -0
  9. data/app/assets/stylesheets/rails_pulse/components/popover.css +0 -1
  10. data/app/assets/stylesheets/rails_pulse/components/row.css +55 -3
  11. data/app/assets/stylesheets/rails_pulse/components/sidebar_menu.css +23 -0
  12. data/app/controllers/concerns/zoom_range_concern.rb +31 -0
  13. data/app/controllers/rails_pulse/application_controller.rb +5 -1
  14. data/app/controllers/rails_pulse/queries_controller.rb +46 -1
  15. data/app/controllers/rails_pulse/requests_controller.rb +14 -1
  16. data/app/controllers/rails_pulse/routes_controller.rb +40 -1
  17. data/app/helpers/rails_pulse/chart_helper.rb +15 -7
  18. data/app/javascript/rails_pulse/application.js +34 -3
  19. data/app/javascript/rails_pulse/controllers/collapsible_controller.js +32 -0
  20. data/app/javascript/rails_pulse/controllers/color_scheme_controller.js +2 -1
  21. data/app/javascript/rails_pulse/controllers/expandable_rows_controller.js +58 -0
  22. data/app/javascript/rails_pulse/controllers/index_controller.js +241 -11
  23. data/app/javascript/rails_pulse/controllers/popover_controller.js +28 -4
  24. data/app/javascript/rails_pulse/controllers/table_sort_controller.js +14 -0
  25. data/app/models/rails_pulse/queries/cards/average_query_times.rb +19 -19
  26. data/app/models/rails_pulse/queries/cards/execution_rate.rb +13 -8
  27. data/app/models/rails_pulse/queries/cards/percentile_query_times.rb +13 -8
  28. data/app/models/rails_pulse/query.rb +46 -0
  29. data/app/models/rails_pulse/routes/cards/average_response_times.rb +17 -19
  30. data/app/models/rails_pulse/routes/cards/error_rate_per_route.rb +13 -8
  31. data/app/models/rails_pulse/routes/cards/percentile_response_times.rb +13 -8
  32. data/app/models/rails_pulse/routes/cards/request_count_totals.rb +13 -8
  33. data/app/services/rails_pulse/analysis/backtrace_analyzer.rb +256 -0
  34. data/app/services/rails_pulse/analysis/base_analyzer.rb +67 -0
  35. data/app/services/rails_pulse/analysis/explain_plan_analyzer.rb +206 -0
  36. data/app/services/rails_pulse/analysis/index_recommendation_engine.rb +326 -0
  37. data/app/services/rails_pulse/analysis/n_plus_one_detector.rb +241 -0
  38. data/app/services/rails_pulse/analysis/query_characteristics_analyzer.rb +146 -0
  39. data/app/services/rails_pulse/analysis/suggestion_generator.rb +217 -0
  40. data/app/services/rails_pulse/query_analysis_service.rb +125 -0
  41. data/app/views/layouts/rails_pulse/_sidebar_menu.html.erb +0 -1
  42. data/app/views/layouts/rails_pulse/application.html.erb +0 -2
  43. data/app/views/rails_pulse/components/_breadcrumbs.html.erb +1 -1
  44. data/app/views/rails_pulse/components/_code_panel.html.erb +17 -3
  45. data/app/views/rails_pulse/components/_empty_state.html.erb +1 -1
  46. data/app/views/rails_pulse/components/_metric_card.html.erb +27 -4
  47. data/app/views/rails_pulse/components/_panel.html.erb +1 -1
  48. data/app/views/rails_pulse/components/_sparkline_stats.html.erb +5 -7
  49. data/app/views/rails_pulse/components/_table_head.html.erb +6 -1
  50. data/app/views/rails_pulse/dashboard/index.html.erb +1 -1
  51. data/app/views/rails_pulse/operations/show.html.erb +17 -15
  52. data/app/views/rails_pulse/queries/_analysis_error.html.erb +15 -0
  53. data/app/views/rails_pulse/queries/_analysis_prompt.html.erb +27 -0
  54. data/app/views/rails_pulse/queries/_analysis_results.html.erb +87 -0
  55. data/app/views/rails_pulse/queries/_analysis_section.html.erb +39 -0
  56. data/app/views/rails_pulse/queries/_show_table.html.erb +1 -1
  57. data/app/views/rails_pulse/queries/_table.html.erb +1 -1
  58. data/app/views/rails_pulse/queries/index.html.erb +48 -51
  59. data/app/views/rails_pulse/queries/show.html.erb +56 -52
  60. data/app/views/rails_pulse/requests/_operations.html.erb +30 -43
  61. data/app/views/rails_pulse/requests/_table.html.erb +3 -1
  62. data/app/views/rails_pulse/requests/index.html.erb +48 -51
  63. data/app/views/rails_pulse/routes/_table.html.erb +1 -1
  64. data/app/views/rails_pulse/routes/index.html.erb +49 -52
  65. data/app/views/rails_pulse/routes/show.html.erb +4 -4
  66. data/config/routes.rb +5 -1
  67. data/db/migrate/20250916031656_add_analysis_to_rails_pulse_queries.rb +13 -0
  68. data/db/rails_pulse_schema.rb +9 -0
  69. data/lib/generators/rails_pulse/convert_to_migrations_generator.rb +65 -0
  70. data/lib/generators/rails_pulse/install_generator.rb +71 -18
  71. data/lib/generators/rails_pulse/templates/migrations/install_rails_pulse_tables.rb +22 -0
  72. data/lib/generators/rails_pulse/templates/migrations/upgrade_rails_pulse_tables.rb +19 -0
  73. data/lib/generators/rails_pulse/upgrade_generator.rb +225 -0
  74. data/lib/rails_pulse/version.rb +1 -1
  75. data/lib/tasks/rails_pulse.rake +27 -8
  76. data/public/rails-pulse-assets/rails-pulse.css +1 -1
  77. data/public/rails-pulse-assets/rails-pulse.css.map +1 -1
  78. data/public/rails-pulse-assets/rails-pulse.js +53 -53
  79. data/public/rails-pulse-assets/rails-pulse.js.map +4 -4
  80. metadata +23 -5
  81. data/app/assets/images/rails_pulse/rails-pulse-logo.png +0 -0
  82. data/app/assets/images/rails_pulse/routes.png +0 -0
  83. data/app/javascript/rails_pulse/controllers/expandable_row_controller.js +0 -67
@@ -0,0 +1,217 @@
1
+ # Consolidates analysis results into prioritized, actionable optimization suggestions.
2
+ # Combines insights from all analyzers and categorizes suggestions by impact and implementation complexity.
3
+ module RailsPulse
4
+ module Analysis
5
+ class SuggestionGenerator
6
+ attr_reader :analysis_results
7
+
8
+ def initialize(analysis_results)
9
+ @analysis_results = analysis_results
10
+ end
11
+
12
+ def generate
13
+ suggestions = []
14
+
15
+ # Suggestions from pattern issues
16
+ suggestions.concat(generate_issue_suggestions)
17
+
18
+ # Suggestions from index recommendations
19
+ suggestions.concat(generate_index_suggestions)
20
+
21
+ # Suggestions from N+1 analysis
22
+ suggestions.concat(generate_n_plus_one_suggestions)
23
+
24
+ # Suggestions from query characteristics
25
+ suggestions.concat(generate_query_characteristic_suggestions)
26
+
27
+ # Suggestions from explain plan issues
28
+ suggestions.concat(generate_explain_plan_suggestions)
29
+
30
+ # Prioritize and deduplicate suggestions
31
+ prioritize_suggestions(suggestions)
32
+ end
33
+
34
+ private
35
+
36
+ def generate_issue_suggestions
37
+ issues = analysis_results.dig(:query_characteristics, :pattern_issues) || []
38
+
39
+ issues.map do |issue|
40
+ case issue[:type]
41
+ when "select_star"
42
+ {
43
+ type: "optimization",
44
+ action: "Specify only needed columns instead of SELECT *",
45
+ benefit: "Reduced memory usage and faster data transfer",
46
+ priority: "medium",
47
+ category: "sql_optimization"
48
+ }
49
+ when "missing_limit"
50
+ {
51
+ type: "optimization",
52
+ action: "Add LIMIT clause to prevent large result sets",
53
+ benefit: "Controlled memory usage and faster response times",
54
+ priority: "high",
55
+ category: "sql_optimization"
56
+ }
57
+ when "missing_where_clause"
58
+ {
59
+ type: "optimization",
60
+ action: "Add WHERE clause to filter results",
61
+ benefit: "Avoid full table scans and reduce data transfer",
62
+ priority: "high",
63
+ category: "sql_optimization"
64
+ }
65
+ when "complex_where_clause"
66
+ {
67
+ type: "refactoring",
68
+ action: "Simplify WHERE clause by breaking into multiple queries or using views",
69
+ benefit: "Easier maintenance and potentially better performance",
70
+ priority: "medium",
71
+ category: "code_quality"
72
+ }
73
+ end
74
+ end.compact
75
+ end
76
+
77
+ def generate_index_suggestions
78
+ recommendations = analysis_results[:index_recommendations] || []
79
+
80
+ recommendations.map do |rec|
81
+ {
82
+ type: "index",
83
+ action: "Add #{rec[:type]} index: #{rec[:migration_code]}",
84
+ benefit: rec[:estimated_benefit],
85
+ priority: rec[:priority],
86
+ migration_code: rec[:migration_code],
87
+ table: rec[:table],
88
+ columns: rec[:columns],
89
+ category: "database_optimization"
90
+ }
91
+ end
92
+ end
93
+
94
+ def generate_n_plus_one_suggestions
95
+ n_plus_one = analysis_results[:n_plus_one_analysis] || {}
96
+ return [] unless n_plus_one[:is_likely_n_plus_one]
97
+
98
+ suggestions = n_plus_one[:suggested_fixes] || []
99
+
100
+ suggestions.map do |fix|
101
+ {
102
+ type: "n_plus_one",
103
+ action: fix[:description],
104
+ benefit: "Eliminate N+1 queries and reduce database load",
105
+ priority: "high",
106
+ code_example: fix[:code_example],
107
+ confidence: n_plus_one[:confidence_score],
108
+ category: "performance_critical"
109
+ }
110
+ end
111
+ end
112
+
113
+ def generate_query_characteristic_suggestions
114
+ stats = analysis_results[:query_characteristics] || {}
115
+ suggestions = []
116
+
117
+ if stats[:join_count] && stats[:join_count] > 3
118
+ suggestions << {
119
+ type: "optimization",
120
+ action: "Review if all #{stats[:join_count]} JOINs are necessary",
121
+ benefit: "Simplified query execution and better performance",
122
+ priority: "medium",
123
+ category: "sql_optimization"
124
+ }
125
+ end
126
+
127
+ if stats[:estimated_complexity] && stats[:estimated_complexity] > 10
128
+ suggestions << {
129
+ type: "refactoring",
130
+ action: "Consider breaking complex query (complexity: #{stats[:estimated_complexity]}) into smaller parts",
131
+ benefit: "Easier maintenance and potentially better performance",
132
+ priority: "medium",
133
+ category: "code_quality"
134
+ }
135
+ end
136
+
137
+ if stats[:has_subqueries] && stats[:join_count] && stats[:join_count] > 1
138
+ suggestions << {
139
+ type: "optimization",
140
+ action: "Consider converting subqueries to JOINs for better performance",
141
+ benefit: "More efficient query execution in most databases",
142
+ priority: "medium",
143
+ category: "sql_optimization"
144
+ }
145
+ end
146
+
147
+ suggestions
148
+ end
149
+
150
+ def generate_explain_plan_suggestions
151
+ explain_issues = analysis_results.dig(:explain_plan, :issues) || []
152
+
153
+ explain_issues.map do |issue|
154
+ case issue[:type]
155
+ when "sequential_scan"
156
+ {
157
+ type: "index",
158
+ action: "Consider adding database indexes for WHERE clause columns",
159
+ benefit: "Dramatically faster query execution",
160
+ priority: "high",
161
+ category: "database_optimization"
162
+ }
163
+ when "temporary_table"
164
+ {
165
+ type: "optimization",
166
+ action: "Optimize query to avoid temporary tables and filesort operations",
167
+ benefit: "Reduced memory usage and faster execution",
168
+ priority: "medium",
169
+ category: "sql_optimization"
170
+ }
171
+ when "high_cost_operation"
172
+ {
173
+ type: "optimization",
174
+ action: "Review query execution plan for high-cost operations",
175
+ benefit: "Identify specific bottlenecks for targeted optimization",
176
+ priority: "high",
177
+ category: "performance_critical"
178
+ }
179
+ when "where_without_index"
180
+ {
181
+ type: "index",
182
+ action: "Add indexes to support WHERE clause conditions",
183
+ benefit: "Eliminate row-by-row filtering during query execution",
184
+ priority: "high",
185
+ category: "database_optimization"
186
+ }
187
+ end
188
+ end.compact
189
+ end
190
+
191
+ def prioritize_suggestions(suggestions)
192
+ # Remove duplicates based on action
193
+ unique_suggestions = suggestions.uniq { |s| s[:action] }
194
+
195
+ # Sort by priority and category
196
+ unique_suggestions.sort_by do |suggestion|
197
+ priority_score = case suggestion[:priority]
198
+ when "high" then 3
199
+ when "medium" then 2
200
+ when "low" then 1
201
+ else 0
202
+ end
203
+
204
+ category_score = case suggestion[:category]
205
+ when "performance_critical" then 4
206
+ when "database_optimization" then 3
207
+ when "sql_optimization" then 2
208
+ when "code_quality" then 1
209
+ else 0
210
+ end
211
+
212
+ [ -priority_score, -category_score, suggestion[:action] ]
213
+ end
214
+ end
215
+ end
216
+ end
217
+ end
@@ -0,0 +1,125 @@
1
+ # Orchestrates comprehensive query analysis using modular analyzers.
2
+ # Coordinates multiple specialized analyzers and consolidates results into actionable insights.
3
+ module RailsPulse
4
+ class QueryAnalysisService
5
+ def self.analyze_query(query_id)
6
+ query = RailsPulse::Query.find(query_id)
7
+ new(query).analyze
8
+ end
9
+
10
+ def initialize(query)
11
+ @query = query
12
+ @operations = fetch_recent_operations
13
+ end
14
+
15
+ def analyze
16
+ # Run all analyzers
17
+ results = {
18
+ analyzed_at: Time.current,
19
+ query_characteristics: analyze_query_characteristics,
20
+ index_recommendations: analyze_index_recommendations,
21
+ n_plus_one_analysis: analyze_n_plus_one,
22
+ explain_plan: analyze_explain_plan,
23
+ backtrace_analysis: analyze_backtraces
24
+ }
25
+
26
+ # Generate consolidated suggestions
27
+ results[:suggestions] = generate_suggestions(results)
28
+
29
+ # Build compatible format for query model
30
+ compatible_results = build_compatible_results(results)
31
+
32
+ # Save results to query
33
+ save_results_to_query(compatible_results)
34
+
35
+ results
36
+ end
37
+
38
+ private
39
+
40
+ def fetch_recent_operations
41
+ @query.operations
42
+ .where("occurred_at > ?", 48.hours.ago)
43
+ .order(occurred_at: :desc)
44
+ .limit(50)
45
+ end
46
+
47
+ def analyze_query_characteristics
48
+ Analysis::QueryCharacteristicsAnalyzer.new(@query, @operations).analyze
49
+ end
50
+
51
+ def analyze_index_recommendations
52
+ Analysis::IndexRecommendationEngine.new(@query, @operations).analyze
53
+ end
54
+
55
+ def analyze_n_plus_one
56
+ Analysis::NPlusOneDetector.new(@query, @operations).analyze
57
+ end
58
+
59
+ def analyze_explain_plan
60
+ return { explain_plan: nil, issues: [] } if @operations.empty?
61
+ Analysis::ExplainPlanAnalyzer.new(@query, @operations).analyze
62
+ end
63
+
64
+ def analyze_backtraces
65
+ return {} if @operations.empty?
66
+ Analysis::BacktraceAnalyzer.new(@query, @operations).analyze
67
+ end
68
+
69
+ def generate_suggestions(analysis_results)
70
+ Analysis::SuggestionGenerator.new(analysis_results).generate
71
+ end
72
+
73
+ # Build compatible format for query model storage
74
+ def build_compatible_results(results)
75
+ characteristics = results[:query_characteristics]
76
+ explain_result = results[:explain_plan]
77
+
78
+ {
79
+ analyzed_at: results[:analyzed_at],
80
+ explain_plan: explain_result[:explain_plan],
81
+ issues: extract_all_issues(characteristics, explain_result),
82
+ metadata: build_metadata(results),
83
+ query_stats: extract_query_stats(characteristics),
84
+ backtrace_analysis: results[:backtrace_analysis],
85
+ index_recommendations: results[:index_recommendations],
86
+ n_plus_one_analysis: results[:n_plus_one_analysis],
87
+ suggestions: results[:suggestions]
88
+ }
89
+ end
90
+
91
+ def extract_all_issues(characteristics, explain_result)
92
+ issues = []
93
+ issues.concat(characteristics[:pattern_issues] || [])
94
+ issues.concat(explain_result[:issues] || [])
95
+ issues
96
+ end
97
+
98
+ def extract_query_stats(characteristics)
99
+ characteristics.except(:pattern_issues)
100
+ end
101
+
102
+ def build_metadata(results)
103
+ {
104
+ analyzers_used: results.keys.reject { |k| k.in?([ :analyzed_at, :suggestions ]) },
105
+ analysis_version: "2.0",
106
+ total_recommendations: results[:index_recommendations]&.count || 0,
107
+ n_plus_one_detected: results.dig(:n_plus_one_analysis, :is_likely_n_plus_one) || false
108
+ }
109
+ end
110
+
111
+ def save_results_to_query(results)
112
+ @query.update!(
113
+ analyzed_at: results[:analyzed_at],
114
+ explain_plan: results[:explain_plan],
115
+ issues: results[:issues],
116
+ metadata: results[:metadata],
117
+ query_stats: results[:query_stats],
118
+ backtrace_analysis: results[:backtrace_analysis],
119
+ index_recommendations: results[:index_recommendations],
120
+ n_plus_one_analysis: results[:n_plus_one_analysis],
121
+ suggestions: results[:suggestions]
122
+ )
123
+ end
124
+ end
125
+ end
@@ -5,7 +5,6 @@
5
5
  </div>
6
6
  <div class="flex flex-col text-start leading-tight overflow-hidden">
7
7
  <span class="overflow-ellipsis font-semibold">Rails Pulse</span>
8
- <span class="overflow-ellipsis text-xs">Open Source</span>
9
8
  </div>
10
9
  </a>
11
10
 
@@ -22,7 +22,6 @@
22
22
  <div class="hide@md" data-controller="rails-pulse--dialog">
23
23
  <button type="button" class="btn btn--icon" data-action="rails-pulse--dialog#showModal">
24
24
  <%= rails_pulse_icon 'menu', width: '20' %>
25
- <span class="sr-only">Open menu</span>
26
25
  </button>
27
26
 
28
27
  <dialog class="sheet sheet--left" style="--sheet-size: 288px;" data-rails-pulse--dialog-target="menu" data-action="click->rails-pulse--dialog#closeOnClickOutside">
@@ -31,7 +30,6 @@
31
30
  <%= link_to rails_pulse.root_path, class: "btn sidebar-menu__button" do %>
32
31
  <div class="flex flex-col text-start leading-tight overflow-hidden">
33
32
  <span class="overflow-ellipsis font-semibold">Rails Pulse</span>
34
- <span class="overflow-ellipsis text-xs">Open Source</span>
35
33
  </div>
36
34
  <% end %>
37
35
  <div class="sidebar-menu__content">
@@ -1,4 +1,4 @@
1
- <nav class="breadcrumb" aria-label="Breadcrumb">
1
+ <nav class="breadcrumb mis-2" aria-label="Breadcrumb">
2
2
  <% breadcrumbs.each_with_index do |crumb, index| %>
3
3
  <% if crumb[:current] %>
4
4
  <span class="text-primary" aria-disabled="true" aria-current="page" role="link"><%= crumb[:title] %></span>
@@ -2,11 +2,25 @@
2
2
  title ||= nil
3
3
  %>
4
4
 
5
- <div>
5
+ <div
6
+ data-controller="rails-pulse--collapsible"
7
+ data-rails-pulse--collapsible-collapsed-class="collapsed"
8
+ class="collapsible-code"
9
+ >
6
10
  <% if title %>
7
- <h2 class="grow font-semibold leading-none mbe-1 uppercase text-xs"><%= title %></h2>
11
+ <h2 class="grow font-semibold leading-none mbe-1 uppercase text-xs">
12
+ <%= title %>
13
+ <button
14
+ type="button"
15
+ class="collapsible-toggle"
16
+ data-rails-pulse--collapsible-target="toggle"
17
+ data-action="click->rails-pulse--collapsible#toggle"
18
+ >
19
+ show more
20
+ </button>
21
+ </h2>
8
22
  <% end %>
9
- <div class="prose max-i-none">
23
+ <div class="prose max-i-none" data-rails-pulse--collapsible-target="content">
10
24
  <pre class="mbs-0" style="white-space: normal; margin-block-end: 0; margin-block-start: 0;"><code><%= html_escape(value) %></code></pre>
11
25
  </div>
12
26
  </div>
@@ -1,7 +1,7 @@
1
1
  <div class="flex items-center justify-center pbs-12 pbe-12 pis-6 pie-6 mb-8">
2
2
  <div class="flex items-center gap">
3
3
  <div class="shrink-0">
4
- <img src="<%= asset_path('search.svg') %>" class="w-32 h-24 opacity-50" alt="No data available" />
4
+ <img src="<%= asset_path('search.svg') %>" class="w-48 h-48" alt="No data available" />
5
5
  </div>
6
6
  <div class="text-subtle pis-8">
7
7
  <p class="text-lg font-semibold mbe-2"><%= title %></p>
@@ -11,12 +11,35 @@
11
11
  %>
12
12
  <div class="grid-item" data-controller="rails-pulse--chart" id="<%= id %>">
13
13
  <%= render 'rails_pulse/components/panel', { title: title, card_classes: 'card-compact' } do %>
14
- <div class="row mbs-2" style="height: 50px; margin-bottom: 0;">
14
+ <div class="row mbs-2" style="--columns: 2; align-items: center; margin-bottom: 0;">
15
15
  <div class="grid-item">
16
16
  <h4 class="text-xl mbs-1 font-bold"><%= summary %></h4>
17
17
  </div>
18
18
  <div class="grid-item">
19
- <%= line_chart line_chart_data, height: "100%", options: sparkline_chart_options %>
19
+ <div class="chart-container chart-container--slim">
20
+ <%
21
+ # Match chart color to trending icon - use hex equivalents of CSS variables
22
+ # These colors match the badge colors exactly
23
+ chart_color = case trend_icon
24
+ when "trending-up"
25
+ "#dc2626" # equivalent to --red-600 (negative trend)
26
+ when "trending-down"
27
+ "#16a34a" # equivalent to --green-600 (positive trend)
28
+ else
29
+ "#ffc91f" # equivalent to --zinc-900 (neutral/primary)
30
+ end
31
+
32
+ chart_options = sparkline_chart_options.deep_merge(
33
+ color: [chart_color],
34
+ series: {
35
+ itemStyle: {
36
+ color: chart_color
37
+ }
38
+ }
39
+ )
40
+ %>
41
+ <%= bar_chart line_chart_data, height: "100%", options: chart_options %>
42
+ </div>
20
43
  </div>
21
44
  </div>
22
45
  <div class="mbs-2" style="height: 10px;">
@@ -30,9 +53,9 @@
30
53
  end
31
54
  %>
32
55
  <div class="flex items-center justify-between">
33
- <span class="badge <%= badge %> p-0">
56
+ <span class="badge <%= badge %> badge--trend p-0">
34
57
  <%= rails_pulse_icon trend_icon, height: "15px", width: "15px", class: "mie-2" %>
35
- <%= trend_amount %>
58
+ <span class="badge__trend-amount"><%= trend_amount %></span>
36
59
  <p class="mis-2 text-subtle text-xs"><%= trend_text %></p>
37
60
  </span>
38
61
  </div>
@@ -15,7 +15,7 @@
15
15
  <% end %>
16
16
  <div class="flex gap items-center">
17
17
  <% if help_heading %>
18
- <div data-controller="rails-pulse--popover" data-rails-pulse--popover-placement-value="bottom-end">
18
+ <div data-controller="rails-pulse--popover" data-rails-pulse--popover-placement-value="bottom-start">
19
19
  <a href="#"
20
20
  data-rails-pulse--popover-target="button"
21
21
  data-action="rails-pulse--popover#toggle"
@@ -1,10 +1,8 @@
1
- <div class="row mbs-2" style="height: 50px; margin-bottom: 0;">
2
- <div class="grid-item">
3
- <h4 class="text-xl mbs-1 font-bold"><%= summary %></h4>
4
- </div>
5
- <div class="grid-item">
6
- <%= line_chart line_chart_data, height: "100%", options: sparkline_chart_options %>
7
- </div>
1
+ <div class="mbs-2">
2
+ <h4 class="text-xl mbs-1 font-bold"><%= summary %></h4>
3
+ </div>
4
+ <div class="chart-container chart-container--slim">
5
+ <%= bar_chart line_chart_data, height: "100%", options: sparkline_chart_options %>
8
6
  </div>
9
7
  <div>
10
8
  <span class="badge badge--<%= trend_direction == "down" ? "positive" : "negative" %>-inverse p-0">
@@ -8,10 +8,15 @@
8
8
  <% sort_params = {} %>
9
9
  <% sort_params[:zoom_start_time] = @zoom_start if @zoom_start.present? %>
10
10
  <% sort_params[:zoom_end_time] = @zoom_end if @zoom_end.present? %>
11
+ <% sort_params[:selected_column_time] = params[:selected_column_time] if params[:selected_column_time].present? %>
11
12
  <%= sort_link @ransack_query, column[:field], column[:label],
12
13
  sort_params.merge(
13
14
  class: "flex items-center",
14
- data: { turbo_prefetch: "false", turbo_action: "replace" }
15
+ data: {
16
+ turbo_prefetch: "false",
17
+ turbo_frame: "index_table",
18
+ action: "click->rails-pulse--table-sort#updateUrl"
19
+ }
15
20
  ) %>
16
21
  <% end %>
17
22
  </th>
@@ -6,7 +6,7 @@
6
6
  </div>
7
7
 
8
8
  <div class="row">
9
- <div class="grid-item" style="height:300px">
9
+ <div class="grid-item">
10
10
  <%= render 'rails_pulse/components/panel', {
11
11
  title: 'Average Response Time',
12
12
  card_classes: 'b-full',
@@ -4,23 +4,25 @@
4
4
 
5
5
  <div class="card">
6
6
  <%= turbo_frame_tag "operation_#{@operation.id}_details" do %>
7
+ <% if @operation.operation_type == "sql" %>
8
+ <div class="mbe-4">
9
+ <%= render 'rails_pulse/components/code_panel', { value: @operation.label } %>
10
+ </div>
11
+ <% end %>
12
+
7
13
  <dl class="descriptive-list">
8
- <dt>
9
- <% if @operation.operation_type == "sql" %>
10
- Query
11
- <% elsif ["template", "partial", "layout", "collection"].include?(@operation.operation_type) %>
12
- View Render
13
- <% else %>
14
- <%= html_escape(@operation.label) %>
15
- <% end %>
16
- </dt>
17
- <dd>
18
- <% if @operation.operation_type == "sql" %>
19
- <%= render 'rails_pulse/components/code_panel', { value: @operation.label } %>
20
- <% else %>
14
+ <% if @operation.operation_type != "sql" %>
15
+ <dt>
16
+ <% if ["template", "partial", "layout", "collection"].include?(@operation.operation_type) %>
17
+ View Render
18
+ <% else %>
19
+ <%= html_escape(@operation.label) %>
20
+ <% end %>
21
+ </dt>
22
+ <dd>
21
23
  <%= html_escape(@operation.label) %>
22
- <% end %>
23
- </dd>
24
+ </dd>
25
+ <% end %>
24
26
 
25
27
  <dt>Operation Type</dt>
26
28
  <dd><pre><%= @operation.operation_type %></pre></dd>
@@ -0,0 +1,15 @@
1
+ <div class="panel panel--danger">
2
+ <div>
3
+ <h3 class="text-sm bold">Analysis Failed</h3>
4
+ <p class="text-sm mt-1">
5
+ <%= error_message %>
6
+ </p>
7
+ <div class="mt-3">
8
+ <%= button_to analyze_query_path(query), method: :post,
9
+ data: { turbo_frame: "query_analysis" },
10
+ class: "btn btn--sm" do %>
11
+ Try Again
12
+ <% end %>
13
+ </div>
14
+ </div>
15
+ </div>
@@ -0,0 +1,27 @@
1
+ <div class="center py-4">
2
+ <h3 class="text-lg mb-2">Analyze Query Performance</h3>
3
+ <p class="mb-4">
4
+ Get detailed insights about this query's performance, potential issues, and optimization suggestions.
5
+ </p>
6
+
7
+ <% if query.has_recent_operations? %>
8
+ <%= button_to analyze_query_path(query), method: :post,
9
+ data: { turbo_frame: "query_analysis" },
10
+ class: "btn btn--primary" do %>
11
+ Analyze Query
12
+ <% end %>
13
+
14
+ <p class="text-sm mt-2">
15
+ Analysis will examine recent executions and provide performance insights.
16
+ </p>
17
+ <% else %>
18
+ <div class="badge badge--warning p-3 mt-3">
19
+ <div>
20
+ <h4 class="text-sm bold">No Recent Data Available</h4>
21
+ <p class="text-sm mt-1">
22
+ This query hasn't been executed recently. Analysis requires recent execution data to provide meaningful insights.
23
+ </p>
24
+ </div>
25
+ </div>
26
+ <% end %>
27
+ </div>