-
Notifications
You must be signed in to change notification settings - Fork 21.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add guides section on verbose query logs to Debugging #34257
Conversation
r? @schneems (@rails-bot has picked a reviewer for you, use r? to override) |
Hey! 👋 thanks for the PR! Overall I like the idea of calling out this debugging feature! My only concern is that people might think that “random” is a method provided by active record if they are skimming. Can we be more explicit about calling it that it’s a user supplied method? You can add “CI skip” to your commit to skip the tests. |
0d70bda
to
6073d5d
Compare
Since this is a useful tool in debugging it made sense to document its existence and usage, especially in the console where it's disabled by default. [ci skip]
6073d5d
to
8c3a228
Compare
@schneems Looks like it was Great idea for the method. Changed it to |
😂 love it. Thanks for the example! |
=> #<Comment id: 2, author: "1", body: "Well, actually...", article_id: 1, created_at: "2018-10-19 00:56:10", updated_at: "2018-10-19 00:56:10"> | ||
``` | ||
|
||
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 identity and address performance problems caused by N+1 queries: single database queries that generates multiple additional queries. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just noticed a typo here: identity
should be identify
.
Hey Nick, good catch. This PR is already merged though. Do you mind submitting another one to fix the typo? Thanks. :-)
…On 4 November 2018 at 12:45:54, Nick Coyne ***@***.******@***.***)) wrote:
@nickcoyne commented on this pull request.
In guides/source/debugging_rails_applications.md(#34257 (comment)):
> +After running `ActiveRecord::Base.verbose_query_logs = true` in the `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: + +``` +irb(main):003:0> Article.pamplemousse + Article Load (0.2ms) SELECT "articles".* FROM "articles" + ↳ app/models/article.rb:5 + Comment Load (0.1ms) SELECT "comments".* FROM "comments" WHERE "comments"."article_id" = ? [["article_id", 1]] + ↳ app/models/article.rb:6 + Comment Load (0.1ms) SELECT "comments".* FROM "comments" WHERE "comments"."article_id" = ? [["article_id", 2]] + ↳ app/models/article.rb:6 + Comment Load (0.1ms) SELECT "comments".* FROM "comments" WHERE "comments"."article_id" = ? [["article_id", 3]] + ↳ app/models/article.rb:6 +=> #<Comment id: 2, author: "1", body: "Well, actually...", article_id: 1, created_at: "2018-10-19 00:56:10", updated_at: "2018-10-19 00:56:10"> +``` + +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 identity and address performance problems caused by N+1 queries: single database queries that generates multiple additional queries.
Just noticed a typo here: identity should be identify.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub(#34257 (review)), or mute the thread(https://github.com/notifications/unsubscribe-auth/AAEBntdEVeyatOJ8CgtukXID0hZsLbdBks5uryfSgaJpZM4XvkjH).
|
Just a small typo fix for the recently merged rails#34257
Since this is a useful tool in debugging it made sense to document its existence and usage, especially in the console where it's disabled by default.
I also amended the
Sending Messages
section right above since it wasn't displaying query callers. Since they're enabled by default in 5.2 it felt appropriate to show them.I might have to go through other guides to make sure we display them when appropriate if showing some logging.
Rendered Preview