You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
After running `ActiveRecord.verbose_query_logs = true` in the `bin/rails console` session to enable verbose query logs and running the method again, it becomes obvious what single line of code is generating all these discrete database calls:
212
+
After enabling `verbose_query_logs` we can see additional information for each query:
Below each database statement you can see arrows pointing to the specific source filename (and line number) of the method that resulted in a database call. This can help you identify and address performance problems caused by N+1 queries: single database queries that generates multiple additional queries.
227
+
Below each database statement you can see arrows pointing to the specific source filename (and line number) of the method that resulted in a database call e.g. `↳ app/models/article.rb:5`.
228
+
229
+
This can help you identify and address performance problems caused by N+1 queries: i.e. single database queries that generate multiple additional queries.
236
230
237
-
Verbose query logs are enabled by default in the development environment logs after Rails 5.2.
231
+
Verbose query logs are [enabled by default](configuring.html#config-active-record-verbose-query-logs) in the development environment logs.
238
232
239
233
WARNING: We recommend against using this setting in production environments. It relies on Ruby's `Kernel#caller` method which tends to allocate a lot of memory in order to generate stacktraces of method calls. Use query log tags (see below) instead.
240
234
241
235
### Verbose Enqueue Logs
242
236
243
237
Similar to the "Verbose Query Logs" above, allows to print source locations of methods that enqueue background jobs.
244
238
245
-
It is enabled by default in development. To enable in other environments, add in `application.rb` or any environment initializer:
239
+
Verbose enqueue logs are [enabled by default](/7_1_release_notes.html#active-job-notable-changes) in the development environment logs.
246
240
247
-
```rb
241
+
```ruby
242
+
# config/environments/development.rb
248
243
config.active_job.verbose_enqueue_logs = true
249
244
```
250
245
251
-
As verbose query logs, it is not recommended for use in production environments.
246
+
```irb
247
+
# bin/rails console
248
+
ActiveJob.verbose_enqueue_logs = true
249
+
```
250
+
251
+
WARNING: We recommend against using this setting in production environments.
252
252
253
253
SQL Query Comments
254
254
------------------
@@ -258,9 +258,7 @@ trace troublesome queries back to the area of the application that generated the
@@ -424,7 +422,7 @@ Besides direct evaluation, the debugger also helps you collect a rich amount of
424
422
425
423
`info` provides an overview of the values of local and instance variables that are visible from the current frame.
426
424
427
-
```rb
425
+
```ruby
428
426
(rdbg) info # command
429
427
%self=#<PostsController:0x0000000000af78>
430
428
@_action_has_layout=true
@@ -444,7 +442,7 @@ Besides direct evaluation, the debugger also helps you collect a rich amount of
444
442
445
443
When used without any options, `backtrace` lists all the frames on the stack:
446
444
447
-
```rb
445
+
```ruby
448
446
=>#0 PostsController#index at ~/projects/rails-guide-example/app/controllers/posts_controller.rb:7
449
447
#1 ActionController::BasicImplicitRender#send_action(method="index", args=[]) at ~/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/actionpack-2.0.alpha/lib/action_controller/metal/basic_implicit_render.rb:6
450
448
#2 AbstractController::Base#process_action(method_name="index", args=[]) at ~/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/actionpack-8.1.0.alpha/lib/abstract_controller/base.rb:214
@@ -484,7 +482,7 @@ It is also possible to use these options together: `backtrace [num] /pattern/`.
0 commit comments