Forum: Ruby on Rails check how long individual active record queries take to the database

Posted by John Merlino (johnmerlino)
on 2013-03-15 17:21
(Received via mailing list)
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?
Posted by Dmitry Maksyoma (Guest)
on 2013-03-16 12:20
(Received via mailing list)
On Saturday, March 16, 2013 5:20:05 AM UTC+13, John Merlino wrote:
> 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?
>
>
If you're using Postgres, you can turn on query times for it. It may be
queries longer than N ms or something.
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.