check how long individual active record queries take to the database

13 views
Skip to first unread message

John Merlino

unread,
Mar 15, 2013, 12:20:05 PM3/15/13
to Ruby on Rails: Talk
I know that Rails output log shows how many milliseconds a sql query
take but I'm looking for something more fine-tuned. I want to know how
long individual activerecord queries take on an indiivdual basis. For
example, I have code that looks like this:

items = current_user.accessible_items
@items = items.where{item_id ==
my{current_user.item_id}}.ordered
@other_items = current_user.accessible_items.where{item_id !=
my{current_user.item_id}}.ordered
@accounts = @other_items.accounts.ordered

There are several database hits here. How can I check how long they
take?

Dmitry Maksyoma

unread,
Mar 16, 2013, 7:19:34 AM3/16/13
to rubyonra...@googlegroups.com
If you're using Postgres, you can turn on query times for it. It may be queries longer than N ms or something. 
Reply all
Reply to author
Forward
0 new messages