Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Add guides section on verbose query logs to Debugging #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
I might have to go through other guides to make sure we display them when appropriate if showing some logging.
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.
Great idea for the method. Changed it to
Oct 19, 2018
1 check passed
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).