rails_mini_profiler 0.1.3 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (74) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +20 -0
  3. data/README.md +42 -18
  4. data/app/assets/javascripts/rails_mini_profiler.js +1 -76
  5. data/app/assets/stylesheets/rails_mini_profiler/application.css +1 -149
  6. data/app/controllers/rails_mini_profiler/application_controller.rb +8 -3
  7. data/app/controllers/rails_mini_profiler/profiled_requests_controller.rb +11 -1
  8. data/app/helpers/rails_mini_profiler/application_helper.rb +11 -0
  9. data/app/{assets/images/rails_mini_profiler → javascript/images}/bookmark.svg +0 -0
  10. data/app/{assets/images/rails_mini_profiler → javascript/images}/chart.svg +0 -0
  11. data/app/{assets/images/rails_mini_profiler → javascript/images}/delete.svg +0 -0
  12. data/app/{assets/images/rails_mini_profiler → javascript/images}/graph.svg +0 -0
  13. data/app/{assets/images/rails_mini_profiler → javascript/images}/logo.svg +0 -0
  14. data/app/{assets/images/rails_mini_profiler → javascript/images}/logo_variant.svg +0 -0
  15. data/app/{assets/images/rails_mini_profiler → javascript/images}/search.svg +0 -0
  16. data/app/{assets/images/rails_mini_profiler → javascript/images}/setting.svg +0 -0
  17. data/app/{assets/images/rails_mini_profiler → javascript/images}/show.svg +0 -0
  18. data/app/javascript/packs/rails-mini-profiler.js +80 -0
  19. data/app/javascript/stylesheets/components/pagination.scss +54 -0
  20. data/app/javascript/stylesheets/flamegraph.scss +9 -0
  21. data/app/{assets/stylesheets/rails_mini_profiler/flashes.css → javascript/stylesheets/flashes.scss} +0 -0
  22. data/app/{assets/stylesheets/rails_mini_profiler/navbar.css → javascript/stylesheets/navbar.scss} +2 -2
  23. data/app/{assets/stylesheets/rails_mini_profiler/profiled_requests.css → javascript/stylesheets/profiled_requests.scss} +1 -7
  24. data/app/javascript/stylesheets/rails-mini-profiler.scss +176 -0
  25. data/app/{assets/stylesheets/rails_mini_profiler/traces.css → javascript/stylesheets/traces.scss} +1 -6
  26. data/app/models/rails_mini_profiler/application_record.rb +1 -1
  27. data/app/presenters/rails_mini_profiler/profiled_request_presenter.rb +2 -2
  28. data/app/views/layouts/rails_mini_profiler/application.html.erb +1 -12
  29. data/app/views/layouts/rails_mini_profiler/flamegraph.html.erb +1 -8
  30. data/app/views/models/_flamegraph.json.jb +3 -0
  31. data/app/views/models/_profiled_request.jb +3 -0
  32. data/app/views/models/_trace.jb +3 -0
  33. data/app/views/rails_mini_profiler/badge.html.erb +1 -1
  34. data/app/views/rails_mini_profiler/flamegraphs/show.json.jb +3 -0
  35. data/app/views/rails_mini_profiler/profiled_requests/index.html.erb +4 -4
  36. data/app/views/rails_mini_profiler/profiled_requests/index.json.jb +3 -0
  37. data/app/views/rails_mini_profiler/profiled_requests/show.json.jb +5 -0
  38. data/app/views/rails_mini_profiler/shared/_head.erb +13 -0
  39. data/app/views/rails_mini_profiler/shared/_navbar.html.erb +1 -1
  40. data/lib/generators/rails_mini_profiler/install_generator.rb +24 -0
  41. data/lib/generators/rails_mini_profiler/templates/rails_mini_profiler.js.erb +13 -0
  42. data/lib/generators/rails_mini_profiler/templates/rails_mini_profiler.rb.erb +23 -7
  43. data/lib/rails_mini_profiler/badge.rb +23 -1
  44. data/lib/rails_mini_profiler/configuration/storage.rb +47 -0
  45. data/lib/rails_mini_profiler/configuration/user_interface.rb +48 -0
  46. data/lib/rails_mini_profiler/configuration.rb +25 -4
  47. data/lib/rails_mini_profiler/engine.rb +8 -1
  48. data/lib/rails_mini_profiler/guard.rb +18 -7
  49. data/lib/rails_mini_profiler/logger.rb +5 -0
  50. data/lib/rails_mini_profiler/middleware.rb +1 -1
  51. data/lib/rails_mini_profiler/models/base_model.rb +5 -0
  52. data/lib/rails_mini_profiler/models/trace.rb +28 -0
  53. data/lib/rails_mini_profiler/redirect.rb +9 -1
  54. data/lib/rails_mini_profiler/request_context.rb +30 -6
  55. data/lib/rails_mini_profiler/request_wrapper.rb +44 -8
  56. data/lib/rails_mini_profiler/tracers.rb +1 -1
  57. data/lib/rails_mini_profiler/version.rb +1 -1
  58. data/lib/rails_mini_profiler.rb +32 -4
  59. data/vendor/assets/images/bookmark.svg +10 -0
  60. data/vendor/assets/images/chart.svg +12 -0
  61. data/vendor/assets/images/delete.svg +9 -0
  62. data/vendor/assets/images/graph.svg +11 -0
  63. data/vendor/assets/images/logo.svg +18 -0
  64. data/vendor/assets/images/logo_variant.svg +32 -0
  65. data/vendor/assets/images/search.svg +10 -0
  66. data/vendor/assets/images/setting.svg +10 -0
  67. data/vendor/assets/images/show.svg +11 -0
  68. data/vendor/assets/javascripts/rails-mini-profiler.css +1 -0
  69. data/vendor/assets/javascripts/rails-mini-profiler.js +1 -0
  70. metadata +74 -24
  71. data/Rakefile +0 -18
  72. data/app/assets/stylesheets/rails_mini_profiler/flamegraph.css +0 -14
  73. data/lib/rails_mini_profiler/errors.rb +0 -8
  74. data/lib/rails_mini_profiler/storage.rb +0 -29
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5967d57f7e1091612b43ac198023ec78af212efd45039cdfd70e9c1cfc030422
4
- data.tar.gz: 5c3e03fd7ef6f6317c95618b3c01d6b0113c09749971e95bebb68bb3ad22bf1a
3
+ metadata.gz: 33db210bbcb4b8ee82f80aa2f88023a478ec4852e9bbcc60cf9f70baf2a0145f
4
+ data.tar.gz: aed097f8f0e418feea8ce2670f173271bea7dd1f8803e542c2f50b82b953932d
5
5
  SHA512:
6
- metadata.gz: 3e8ab13ca5a216ce467d853bfe65cbed989286b290c40d930eeb913594630779e57584dc8526bb93985b84478ceac48a2867d1c80182a501e9c2e5f312bc98b5
7
- data.tar.gz: cff4e83fefaabb3c1d7db55e03d2a4353b3a3ded37f17a96dcf189c549df98c403c182579822602023c70aee6495d9366a9f0351a275e53aea4af2fcce573dfd
6
+ metadata.gz: a6cc1c0d0e05949bb360d4e5d04091bcfb16419a80ca31361d617a1a34571d28dfc33f31820075646143b9a359b12aa66c9ec67bb859bbdc25feaca062b5adb8
7
+ data.tar.gz: c6673b79dc6b8aacd205b5b368c1e044fb8b0e595fbb41371cf6f2c667fe31875cea9376ea551cb0e39a6c13c57cd654f41342b09bc4f41a1084a03092804fe9
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2021 hschne
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -8,7 +8,7 @@
8
8
 
9
9
  [![Gem Version](https://badge.fury.io/rb/rails_mini_profiler.svg)](https://badge.fury.io/rb/rails_mini_profiler)
10
10
  [![Main](https://github.com/hschne/rails-mini-profiler/actions/workflows/main.yml/badge.svg)](https://github.com/hschne/rails-mini-profiler/actions/workflows/main.yml)
11
- [![Main](https://img.shields.io/github/license/hschne/rails-mini-profiler)](https://img.shields.io/github/license/hschne/rails-mini-profiler)
11
+ [![License](https://img.shields.io/github/license/hschne/rails-mini-profiler)](https://img.shields.io/github/license/hschne/rails-mini-profiler)
12
12
 
13
13
  [![Maintainability](https://api.codeclimate.com/v1/badges/1fcc2f4d01ab5bf7a260/maintainability)](https://codeclimate.com/github/hschne/rails-mini-profiler/maintainability)
14
14
  [![Test Coverage](https://api.codeclimate.com/v1/badges/1fcc2f4d01ab5bf7a260/test_coverage)](https://codeclimate.com/github/hschne/rails-mini-profiler/test_coverage)
@@ -91,34 +91,36 @@ By clicking on individual traces you can find out detailed information.
91
91
 
92
92
  ### Flamegraphs
93
93
 
94
- Rails Mini Profiler per default records Flamegraphs for every profiled request for convenience. Note that Flamegraphs recording
95
- incur a significant performance penalty, and can take up a lot of space.
94
+ Rails Mini Profiler automatically records Flamegraphs for profiled requests. To enable this feature, add [Stackprof](https://github.com/tmm1/stackprof)
95
+ to your Gemfile:
96
96
 
97
- To change the default behavior see [Configuration](#Configuration).
97
+ ```ruby
98
+ gem 'stackprof'
99
+ ```
100
+
101
+ For convenience, Flamegraphs are recorded for every request. This may incur a significant performance penalty. To change the default behavior see [Configuration](#Configuration).
98
102
 
99
- Flamegraphs are rendered using [Speedscope](https://github.com/jlfwong/speedscope). If Flamegraphs are not rendering
100
- you may have to amend your content security policy. See [Troubleshooting](#Troubleshooting)
103
+ Flamegraphs are rendered using [Speedscope](https://github.com/jlfwong/speedscope). See [Troubleshooting](#Troubleshooting) if Flamegraphs are not rendering correctly.
101
104
 
102
105
  ## Configuration
103
106
 
104
- You can set the following configuration options in Rails Mini Profiler:
107
+ Rails Mini Profiler provides a wide array of configuration options. You can find details below. For an example configuration check `initializers/rails_mini_profiler.rb` (or [the template file](https://github.com/hschne/rails-mini-profiler/blob/main/lib/generators/rails_mini_profiler/templates/rails_mini_profiler.rb.erb)).
105
108
 
106
- | Option | Default | Description |
107
- | ------------------------ | ---------------------------- | ----------------------------------------------------------------------------------------------- |
109
+ | Name | Default | Description |
110
+ |--------------------------|------------------------------|-------------------------------------------------------------------------------------------------|
108
111
  | `enabled` | `true` (dev)/ `false` (prod) | Whether or not RMP is enabled |
109
- | `badge_enabled` | `true` | Should the hedgehog 🦔 badge be injected into pages? |
110
- | `badge_position` | `'top-left'` | Where to display the badge. Options are `'top-left', 'top-right', 'bottom-left, 'bottom-right'` |
111
112
  | `flamegraph_enabled` | `true` | Should flamegraphs be recorded automatically? |
112
113
  | `flamegraph_sample_rate` | `0.5` | The flamegraph sample rate. How many snapshots per millisecond are created. |
113
114
  | `skip_paths` | `[]` | An array of request paths that should not be profiled. Regex allowed. |
114
- | `storage` | `Storage` | Storage configuration. See [Storage](#Storage) |
115
+ | `storage` | `Storage.new` | Storage configuration. See [Storage](#Storage). |
116
+ | `ui` | `UserInterface.new` | UI configuration. See [UI](#UI). |
115
117
  | `user_provider` | `Rack::Request.new(env).ip` | How to identify users. See [Users](#Users) |
116
118
 
117
119
  ### Request Configuration
118
120
 
119
121
  You may override the configuration by sending request parameters. The following parameters are available:
120
122
 
121
- | Option | Description |
123
+ | Name | Description |
122
124
  | ---------------- | ------------------------------------------------------------------------------------------- |
123
125
  | `rmp_flamegraph` | Overrides `flamegraph_enabled` If set to `true` will redirect to the flamegraph immediatly. |
124
126
 
@@ -127,7 +129,7 @@ You may override the configuration by sending request parameters. The following
127
129
  Rails Mini Profiler stores profiling information in your database per default. You can configure various details of how
128
130
  traces and requests are stored.
129
131
 
130
- | Configuration | Default | Description |
132
+ | Name | Default | Description |
131
133
  | ------------------------- | ----------------------- | --------------------------------------------------------------------------------------------------------- |
132
134
  | `database` | `nil` | Set a custom database to be used for storing profiler information. Uses `connect_to` for profiler records |
133
135
  | `profiled_requests_table` | `rmp_profiled_requests` | The table to be used to store profiled requests. |
@@ -136,7 +138,7 @@ traces and requests are stored.
136
138
 
137
139
  Rails Mini Profiler does not offer an automatic way to clean up old profiling information. It is recommended you add a sweeper job to clean up old profiled requests periodically (e.g. using [clockwork](https://github.com/adamwiggins/clockwork). For example, with ActiveJob:
138
140
 
139
- ```
141
+ ```ruby
140
142
  # Clockwork
141
143
  every(1.month, 'purge rails mini profiler' do
142
144
  ProfiledRequestCleanupJob.perform_later
@@ -152,6 +154,16 @@ class ProfiledRequestCleanupJob < ApplicationJob
152
154
  end
153
155
  ```
154
156
 
157
+ ### UI
158
+
159
+ Rails Mini Profiler allows you to configure various UI features.
160
+
161
+ | Name | Default | Description |
162
+ |------------------|--------------|-------------------------------------------------------------------------------------------------|
163
+ | `badge_enabled` | `true` | Should the hedgehog 🦔 badge be injected into pages? |
164
+ | `badge_position` | `'top-left'` | Where to display the badge. Options are `'top-left', 'top-right', 'bottom-left, 'bottom-right'` |
165
+ | `page_size` | `25` | The page size for lists shown in the UI. |
166
+
155
167
  ### Users
156
168
 
157
169
  Profiling information is segregated by user ID. That means users cannot see each other's profiled requests.
@@ -166,8 +178,6 @@ You may also explicitly set the user from the application itself:
166
178
 
167
179
  ```ruby
168
180
  class ApplicationController < ActionController::Base
169
- ...
170
-
171
181
  before_action do
172
182
  RailsMiniProfiler::User.authorize(current_user.id)
173
183
  end
@@ -214,7 +224,13 @@ As such, compared to `rack-mini-profiler`, it does not support non-Rails apps (e
214
224
 
215
225
  Rails Mini Profiler is in early development. As such, breaking changes may still be introduced on a regular basis. While Rails Mini Profiler is in pre-release we do not offer upgrade migrations.
216
226
 
217
- If an upgrade to Rails Mini Profiler breaks your application, we recommend that you drop the offending tables and re-run migrations for the latest version:
227
+ If an upgrade to Rails Mini Profiler breaks your application, we recommend that you clean house and start over. Re-run the initializer and overwrite existing files:
228
+
229
+ ```bash
230
+ rails rails_mini_profiler:install
231
+ ```
232
+
233
+ If only the DB schema is out of date, drop the offending tables and re-run migrations for the latest version:
218
234
 
219
235
  ```
220
236
  rails rails_mini_profiler:install:migrations
@@ -243,6 +259,14 @@ end
243
259
 
244
260
  **Note: Sprockets and flash are currently required for some of Rails Mini Profiler's UI features. These modifications may no longer be needed in the future.
245
261
 
262
+ ### No Flamegraphs are being recored?
263
+
264
+ Make sure you have added [StackProf](https://github.com/tmm1/stackprof) to your Gemfile.
265
+
266
+ ```ruby
267
+ gem 'stackprof'
268
+ ```
269
+
246
270
  ### Flamegraphs are not rendering?
247
271
 
248
272
  Flamegraphs are loaded into [Speedscope](https://github.com/jlfwong/speedscope) using an Iframe and URI Encoded blobs (see [source](https://github.com/hschne/rails-mini-profiler/blob/main/app/views/rails_mini_profiler/flamegraphs/show.html.erb))
@@ -12,79 +12,4 @@
12
12
  //
13
13
  //= require rails-ujs
14
14
  //= require_tree .
15
-
16
- function setupRequestSearch() {
17
- const profiledRequestNameSearch = document.getElementById('profiled-request-search')
18
- if (profiledRequestNameSearch) {
19
- profiledRequestNameSearch.addEventListener('keyup', function (event) {
20
- if (event.key === 'Enter') {
21
- event.preventDefault()
22
- document.getElementById('profiled-request-search-form').submit()
23
- }
24
- })
25
- }
26
- }
27
-
28
- function setupTraceSearch() {
29
- const traceNameSearch = document.getElementById('trace-search')
30
- if (traceNameSearch) {
31
- traceNameSearch.addEventListener('keyup', function (event) {
32
- if (event.key === 'Enter') {
33
- event.preventDefault()
34
- document.getElementById('trace-form').submit()
35
- }
36
- })
37
- }
38
- }
39
-
40
- function setupRequestTable() {
41
- const profiledRequestTable = document.getElementById('profiled-requests-table');
42
- if (profiledRequestTable) {
43
- const rows = profiledRequestTable.getElementsByTagName('tr')
44
- for (let i = 0; i < rows.length; i++) {
45
- const currentRow = profiledRequestTable.rows[i]
46
- const link = currentRow.dataset.link
47
- const createClickHandler = function (currentRow) {
48
- return function () {
49
- window.location.href = link
50
- }
51
- }
52
- currentRow.onclick = createClickHandler(currentRow)
53
- }
54
- }
55
- }
56
-
57
- function setupTraceBars () {
58
- const traceBars = document.querySelectorAll('.trace-bar')
59
- traceBars.forEach((bar) => {
60
- const popover = bar.children[0]
61
- tippy(bar, {
62
- trigger: 'click',
63
- content: popover,
64
- theme: 'rmp',
65
- maxWidth: '700px',
66
- placement: 'bottom',
67
- interactive: true,
68
- onShow (instance) {
69
- instance.popper.querySelector('.popover-close').addEventListener('click', () => {
70
- instance.hide()
71
- })
72
- },
73
- onHide (instance) {
74
- instance.popper.querySelector('.popover-close').removeEventListener('click', () => {
75
- instance.hide()
76
- })
77
- },
78
- })
79
- })
80
- }
81
-
82
-
83
- // Trace Bar Popovers
84
- document.addEventListener('DOMContentLoaded', () => {
85
- setupRequestTable();
86
- setupRequestSearch();
87
- setupTraceBars();
88
- setupTraceSearch();
89
- }, false)
90
-
15
+ //= require rails-mini-profiler
@@ -12,153 +12,5 @@
12
12
  *
13
13
  *= require_tree .
14
14
  *= require_self
15
+ *= require rails-mini-profiler
15
16
  */
16
-
17
- html {
18
- width: 100%;
19
- height: 100%;
20
- margin: 0;
21
- padding: 0;
22
-
23
- --grey-50: #F9FAFB;
24
- --grey-100: #F3F4F6;
25
- --grey-200: #E5E7EB;
26
- --grey-400: #9CA3AF;
27
- --grey-500: #6B7280;
28
- --grey-700: #374151;
29
- --grey-900: #111827;
30
-
31
- --red-400: #F87171;
32
- --red-500: #EF4444;
33
- --red-600: #DC2626;
34
-
35
- --yellow-400: #FBBF24;
36
- --yellow-500: #F59E0B;
37
-
38
- --green-300: #6EE7B7;
39
- --green-400: #34D399;
40
- --green-500: #10B981;
41
-
42
- --blue-400: #60A5FA;
43
- --blue-500: #3B82F6;
44
-
45
- --main-width: 1056px;
46
-
47
- --primary: var(--red-600);
48
-
49
- --border-color: var(--grey-200);
50
- --text-color: var(--grey-900);
51
-
52
- font-family: 'Open Sans', sans-serif;
53
- }
54
-
55
- body {
56
- width: 100%;
57
- height: 100%;
58
- margin: 0;
59
- padding: 0;
60
-
61
- color: var(--text-color)
62
- }
63
-
64
- h1 {
65
- padding: 2rem 0 1rem;
66
- }
67
-
68
- button {
69
- border: none;
70
- border-radius: .25rem;
71
- padding: 0.5em .5em;
72
- text-align: center;
73
- text-decoration: none;
74
- display: inline-block;
75
- font-size: 1rem;
76
- cursor: pointer;
77
- }
78
-
79
- button:hover {
80
- box-shadow: 0 .25rem .25rem 0 var(--grey-50);
81
- }
82
-
83
- /* --------------------------------------- */
84
-
85
- .text-left {
86
- text-align: left;
87
- }
88
-
89
- .text-right {
90
- text-align: right;
91
- }
92
-
93
- /* --------------------------------------- */
94
-
95
- .pill {
96
- margin: .2rem 0;
97
- padding: .1rem .4rem;
98
- border-radius: 5px;
99
-
100
- font-size: .9rem;
101
- font-weight: 600;
102
- letter-spacing: .1rem;
103
-
104
- background: var(--grey-200);
105
- }
106
-
107
- /* --------------------------------------- */
108
-
109
- .popover {
110
- display: flex;
111
- flex-direction: column;
112
- width: 600px;
113
- padding: 1em;
114
- color: black;
115
- }
116
-
117
- .popover-header {
118
- display: flex;
119
- padding-bottom: 1em;
120
- flex-direction: row;
121
- justify-content: space-between;
122
- align-items: center;
123
- }
124
-
125
- .popover-description {
126
- margin: 0;
127
- padding: 0;
128
- }
129
-
130
- .popover-close {
131
- background: transparent;
132
- padding: 0;
133
- font-weight: 700;
134
- font-size: 20px;
135
- color: var(--grey-400);
136
- }
137
-
138
- .popover-body {
139
- padding: 1em 0;
140
- }
141
-
142
- .popover-footer {
143
- border-top: 1px solid var(--grey-50);
144
- }
145
-
146
- .tippy-box[data-theme~='rmp'] {
147
- background: white;
148
- box-shadow: 8px 0 30px 4px rgba(0, 0, 0, .2), 8px 4px 10px 0 rgba(0, 0, 0, .05);
149
- border-radius: 3px;
150
-
151
- transition: all cubic-bezier(.19,1,.22,1) .2s;
152
- }
153
- .tippy-box[data-theme~='rmp'][data-placement^='top'] > .tippy-arrow::before {
154
- border-top-color: white;
155
- }
156
- .tippy-box[data-theme~='rmp'][data-placement^='bottom'] > .tippy-arrow::before {
157
- border-bottom-color: white;
158
- }
159
- .tippy-box[data-theme~='rmp'][data-placement^='left'] > .tippy-arrow::before {
160
- border-left-color: white;
161
- }
162
- .tippy-box[data-theme~='rmp'][data-placement^='right'] > .tippy-arrow::before {
163
- border-right-color: white;
164
- }
@@ -2,7 +2,9 @@
2
2
 
3
3
  module RailsMiniProfiler
4
4
  class ApplicationController < ActionController::Base
5
- rescue_from ActiveRecord::RecordNotFound, with: :not_found
5
+ include Pagy::Backend
6
+
7
+ rescue_from ActiveRecord::RecordNotFound, with: ->(error) { handle(error, 404) }
6
8
 
7
9
  before_action :check_current_user
8
10
 
@@ -17,8 +19,11 @@ module RailsMiniProfiler
17
19
 
18
20
  private
19
21
 
20
- def not_found(error)
21
- redirect_back(fallback_location: profiled_requests_path, alert: error.to_s)
22
+ def handle(error, status = 500)
23
+ respond_to do |format|
24
+ format.html { redirect_back(fallback_location: profiled_requests_path, alert: error.to_s) }
25
+ format.json { render status: status, json: { message: error.to_s } }
26
+ end
22
27
  end
23
28
 
24
29
  def check_current_user
@@ -11,12 +11,13 @@ module RailsMiniProfiler
11
11
  .includes(:flamegraph)
12
12
  .where(user_id: user_id).order(id: :desc)
13
13
  @profiled_requests = @profiled_requests.where('request_path LIKE ?', "%#{params[:path]}%") if params[:path]
14
+ @pagy, @profiled_requests = pagy(@profiled_requests, items: configuration.ui.page_size)
14
15
  @profiled_requests = @profiled_requests.map { |request| present(request) }
15
16
  end
16
17
 
17
18
  def show
18
19
  @traces = @profiled_request.traces
19
- @traces = @traces.where('payload LIKE ?', "%#{params[:search]}%") if params[:search]
20
+ @traces = @traces.where("#{payload_column} LIKE ?", "%#{params[:search]}%") if params[:search]
20
21
  @traces = @traces
21
22
  .order(:start)
22
23
  .map { |trace| present(trace, profiled_request: @profiled_request) }
@@ -51,5 +52,14 @@ module RailsMiniProfiler
51
52
  def configuration
52
53
  @configuration ||= RailsMiniProfiler.configuration
53
54
  end
55
+
56
+ def payload_column
57
+ if ActiveRecord::Base.connection.adapter_name == 'PostgreSQL'
58
+ # Cast json field to text to have access to the LIKE operator
59
+ 'payload::text'
60
+ else
61
+ 'payload'
62
+ end
63
+ end
54
64
  end
55
65
  end