Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3980816
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T05:20:09+00:00 2026-05-20T05:20:09+00:00

Just doing some Rails and noticed that when displaying 30 products on a single

  • 0

Just doing some Rails and noticed that when displaying 30 products on a single page using @products.each do it appears as though there are a lot of queries going on in the background, see below for my console output. Is this right or am I reading this entirely wrong?

Category Load (0.1ms)  SELECT "categories".* FROM "categories" WHERE ("categories"."name" = 'bras') LIMIT 1
  Product Load (28.0ms)  SELECT "products".* FROM "products" WHERE ("products".category_id = 48)
  Brand Load (0.2ms)  SELECT "brands".* FROM "brands" WHERE ("brands"."id" = 408) LIMIT 1
  Category Load (0.1ms)  SELECT "categories".* FROM "categories" WHERE ("categories"."id" = 48) LIMIT 1
  Merchant Load (0.1ms)  SELECT "merchants".* FROM "merchants" WHERE ("merchants"."id" = 2) LIMIT 1
Rendered products/_product.html.erb (16.9ms)
  CACHE (0.0ms)  SELECT "brands".* FROM "brands" WHERE ("brands"."id" = 408) LIMIT 1
  CACHE (0.0ms)  SELECT "categories".* FROM "categories" WHERE ("categories"."id" = 48) LIMIT 1
  CACHE (0.0ms)  SELECT "merchants".* FROM "merchants" WHERE ("merchants"."id" = 2) LIMIT 1
Rendered products/_product.html.erb (1.8ms)
  CACHE (0.0ms)  SELECT "brands".* FROM "brands" WHERE ("brands"."id" = 408) LIMIT 1
  CACHE (0.0ms)  SELECT "categories".* FROM "categories" WHERE ("categories"."id" = 48) LIMIT 1
  CACHE (0.0ms)  SELECT "merchants".* FROM "merchants" WHERE ("merchants"."id" = 2) LIMIT 1
Rendered products/_product.html.erb (1.5ms)
  CACHE (0.0ms)  SELECT "brands".* FROM "brands" WHERE ("brands"."id" = 408) LIMIT 1
  CACHE (0.0ms)  SELECT "categories".* FROM "categories" WHERE ("categories"."id" = 48) LIMIT 1
  CACHE (0.0ms)  SELECT "merchants".* FROM "merchants" WHERE ("merchants"."id" = 2) LIMIT 1
Rendered products/_product.html.erb (1.5ms)
  CACHE (0.0ms)  SELECT "brands".* FROM "brands" WHERE ("brands"."id" = 408) LIMIT 1
  CACHE (0.0ms)  SELECT "categories".* FROM "categories" WHERE ("categories"."id" = 48) LIMIT 1
  CACHE (0.0ms)  SELECT "merchants".* FROM "merchants" WHERE ("merchants"."id" = 2) LIMIT 1
Rendered products/_product.html.erb (1.5ms)
  CACHE (0.0ms)  SELECT "brands".* FROM "brands" WHERE ("brands"."id" = 408) LIMIT 1
  CACHE (0.0ms)  SELECT "categories".* FROM "categories" WHERE ("categories"."id" = 48) LIMIT 1
  CACHE (0.0ms)  SELECT "merchants".* FROM "merchants" WHERE ("merchants"."id" = 2) LIMIT 1
Rendered products/_product.html.erb (1.5ms)
  CACHE (0.0ms)  SELECT "brands".* FROM "brands" WHERE ("brands"."id" = 408) LIMIT 1
  CACHE (0.0ms)  SELECT "categories".* FROM "categories" WHERE ("categories"."id" = 48) LIMIT 1
  CACHE (0.0ms)  SELECT "merchants".* FROM "merchants" WHERE ("merchants"."id" = 2) LIMIT 1
Rendered products/_product.html.erb (1.5ms)
  CACHE (0.0ms)  SELECT "brands".* FROM "brands" WHERE ("brands"."id" = 408) LIMIT 1
  CACHE (0.0ms)  SELECT "categories".* FROM "categories" WHERE ("categories"."id" = 48) LIMIT 1
  CACHE (0.0ms)  SELECT "merchants".* FROM "merchants" WHERE ("merchants"."id" = 2) LIMIT 1
Rendered products/_product.html.erb (1.5ms)
  CACHE (0.0ms)  SELECT "brands".* FROM "brands" WHERE ("brands"."id" = 408) LIMIT 1
  CACHE (0.0ms)  SELECT "categories".* FROM "categories" WHERE ("categories"."id" = 48) LIMIT 1
  CACHE (0.0ms)  SELECT "merchants".* FROM "merchants" WHERE ("merchants"."id" = 2) LIMIT 1
Rendered products/_product.html.erb (1.7ms)
  CACHE (0.0ms)  SELECT "brands".* FROM "brands" WHERE ("brands"."id" = 408) LIMIT 1
  CACHE (0.0ms)  SELECT "categories".* FROM "categories" WHERE ("categories"."id" = 48) LIMIT 1
  CACHE (0.0ms)  SELECT "merchants".* FROM "merchants" WHERE ("merchants"."id" = 2) LIMIT 1
Rendered products/_product.html.erb (1.4ms)
  CACHE (0.0ms)  SELECT "brands".* FROM "brands" WHERE ("brands"."id" = 408) LIMIT 1
  CACHE (0.0ms)  SELECT "categories".* FROM "categories" WHERE ("categories"."id" = 48) LIMIT 1
  CACHE (0.0ms)  SELECT "merchants".* FROM "merchants" WHERE ("merchants"."id" = 2) LIMIT 1
Rendered products/_product.html.erb (1.5ms)
  CACHE (0.0ms)  SELECT "brands".* FROM "brands" WHERE ("brands"."id" = 408) LIMIT 1
  CACHE (0.0ms)  SELECT "categories".* FROM "categories" WHERE ("categories"."id" = 48) LIMIT 1
  CACHE (0.0ms)  SELECT "merchants".* FROM "merchants" WHERE ("merchants"."id" = 2) LIMIT 1
Rendered products/_product.html.erb (1.4ms)
  CACHE (0.0ms)  SELECT "brands".* FROM "brands" WHERE ("brands"."id" = 408) LIMIT 1
  CACHE (0.0ms)  SELECT "categories".* FROM "categories" WHERE ("categories"."id" = 48) LIMIT 1
  CACHE (0.0ms)  SELECT "merchants".* FROM "merchants" WHERE ("merchants"."id" = 2) LIMIT 1
Rendered products/_product.html.erb (1.5ms)
  CACHE (0.0ms)  SELECT "brands".* FROM "brands" WHERE ("brands"."id" = 408) LIMIT 1
  CACHE (0.0ms)  SELECT "categories".* FROM "categories" WHERE ("categories"."id" = 48) LIMIT 1
  CACHE (0.0ms)  SELECT "merchants".* FROM "merchants" WHERE ("merchants"."id" = 2) LIMIT 1
Rendered products/_product.html.erb (1.5ms)
  CACHE (0.0ms)  SELECT "brands".* FROM "brands" WHERE ("brands"."id" = 408) LIMIT 1
  CACHE (0.0ms)  SELECT "categories".* FROM "categories" WHERE ("categories"."id" = 48) LIMIT 1
  CACHE (0.0ms)  SELECT "merchants".* FROM "merchants" WHERE ("merchants"."id" = 2) LIMIT 1
Rendered products/_product.html.erb (1.6ms)
  CACHE (0.0ms)  SELECT "brands".* FROM "brands" WHERE ("brands"."id" = 408) LIMIT 1
  CACHE (0.0ms)  SELECT "categories".* FROM "categories" WHERE ("categories"."id" = 48) LIMIT 1
  CACHE (0.0ms)  SELECT "merchants".* FROM "merchants" WHERE ("merchants"."id" = 2) LIMIT 1
Rendered products/_product.html.erb (1.5ms)
  CACHE (0.0ms)  SELECT "brands".* FROM "brands" WHERE ("brands"."id" = 408) LIMIT 1
  CACHE (0.0ms)  SELECT "categories".* FROM "categories" WHERE ("categories"."id" = 48) LIMIT 1
  CACHE (0.0ms)  SELECT "merchants".* FROM "merchants" WHERE ("merchants"."id" = 2) LIMIT 1
Rendered products/_product.html.erb (1.5ms)
  CACHE (0.0ms)  SELECT "brands".* FROM "brands" WHERE ("brands"."id" = 408) LIMIT 1
  CACHE (0.0ms)  SELECT "categories".* FROM "categories" WHERE ("categories"."id" = 48) LIMIT 1
  CACHE (0.0ms)  SELECT "merchants".* FROM "merchants" WHERE ("merchants"."id" = 2) LIMIT 1
Rendered products/_product.html.erb (1.5ms)
  CACHE (0.0ms)  SELECT "brands".* FROM "brands" WHERE ("brands"."id" = 408) LIMIT 1
  CACHE (0.0ms)  SELECT "categories".* FROM "categories" WHERE ("categories"."id" = 48) LIMIT 1
  CACHE (0.0ms)  SELECT "merchants".* FROM "merchants" WHERE ("merchants"."id" = 2) LIMIT 1
Rendered products/_product.html.erb (1.5ms)
  CACHE (0.0ms)  SELECT "brands".* FROM "brands" WHERE ("brands"."id" = 408) LIMIT 1
  CACHE (0.0ms)  SELECT "categories".* FROM "categories" WHERE ("categories"."id" = 48) LIMIT 1
  CACHE (0.0ms)  SELECT "merchants".* FROM "merchants" WHERE ("merchants"."id" = 2) LIMIT 1
Rendered products/_product.html.erb (1.6ms)
  CACHE (0.0ms)  SELECT "brands".* FROM "brands" WHERE ("brands"."id" = 408) LIMIT 1
  CACHE (0.0ms)  SELECT "categories".* FROM "categories" WHERE ("categories"."id" = 48) LIMIT 1
  CACHE (0.0ms)  SELECT "merchants".* FROM "merchants" WHERE ("merchants"."id" = 2) LIMIT 1
Rendered products/_product.html.erb (1.4ms)
  CACHE (0.0ms)  SELECT "brands".* FROM "brands" WHERE ("brands"."id" = 408) LIMIT 1
  CACHE (0.0ms)  SELECT "categories".* FROM "categories" WHERE ("categories"."id" = 48) LIMIT 1
  CACHE (0.0ms)  SELECT "merchants".* FROM "merchants" WHERE ("merchants"."id" = 2) LIMIT 1
Rendered products/_product.html.erb (1.5ms)
  CACHE (0.0ms)  SELECT "brands".* FROM "brands" WHERE ("brands"."id" = 408) LIMIT 1
  CACHE (0.0ms)  SELECT "categories".* FROM "categories" WHERE ("categories"."id" = 48) LIMIT 1
  CACHE (0.0ms)  SELECT "merchants".* FROM "merchants" WHERE ("merchants"."id" = 2) LIMIT 1
Rendered products/_product.html.erb (1.5ms)
  CACHE (0.0ms)  SELECT "brands".* FROM "brands" WHERE ("brands"."id" = 408) LIMIT 1
  CACHE (0.0ms)  SELECT "categories".* FROM "categories" WHERE ("categories"."id" = 48) LIMIT 1
  CACHE (0.0ms)  SELECT "merchants".* FROM "merchants" WHERE ("merchants"."id" = 2) LIMIT 1
Rendered products/_product.html.erb (2.0ms)
  CACHE (0.0ms)  SELECT "brands".* FROM "brands" WHERE ("brands"."id" = 408) LIMIT 1
  CACHE (0.0ms)  SELECT "categories".* FROM "categories" WHERE ("categories"."id" = 48) LIMIT 1
  CACHE (0.0ms)  SELECT "merchants".* FROM "merchants" WHERE ("merchants"."id" = 2) LIMIT 1
Rendered products/_product.html.erb (1.4ms)
  CACHE (0.0ms)  SELECT "brands".* FROM "brands" WHERE ("brands"."id" = 408) LIMIT 1
  CACHE (0.0ms)  SELECT "categories".* FROM "categories" WHERE ("categories"."id" = 48) LIMIT 1
  CACHE (0.0ms)  SELECT "merchants".* FROM "merchants" WHERE ("merchants"."id" = 2) LIMIT 1
Rendered products/_product.html.erb (1.5ms)
  CACHE (0.0ms)  SELECT "brands".* FROM "brands" WHERE ("brands"."id" = 408) LIMIT 1
  CACHE (0.0ms)  SELECT "categories".* FROM "categories" WHERE ("categories"."id" = 48) LIMIT 1
  CACHE (0.0ms)  SELECT "merchants".* FROM "merchants" WHERE ("merchants"."id" = 2) LIMIT 1
Rendered products/_product.html.erb (1.5ms)
  CACHE (0.0ms)  SELECT "brands".* FROM "brands" WHERE ("brands"."id" = 408) LIMIT 1
  CACHE (0.0ms)  SELECT "categories".* FROM "categories" WHERE ("categories"."id" = 48) LIMIT 1
  CACHE (0.0ms)  SELECT "merchants".* FROM "merchants" WHERE ("merchants"."id" = 2) LIMIT 1
Rendered products/_product.html.erb (1.6ms)
  CACHE (0.0ms)  SELECT "brands".* FROM "brands" WHERE ("brands"."id" = 408) LIMIT 1
  CACHE (0.0ms)  SELECT "categories".* FROM "categories" WHERE ("categories"."id" = 48) LIMIT 1
  CACHE (0.0ms)  SELECT "merchants".* FROM "merchants" WHERE ("merchants"."id" = 2) LIMIT 1
Rendered products/_product.html.erb (1.5ms)
  CACHE (0.0ms)  SELECT "brands".* FROM "brands" WHERE ("brands"."id" = 408) LIMIT 1
  CACHE (0.0ms)  SELECT "categories".* FROM "categories" WHERE ("categories"."id" = 48) LIMIT 1
  CACHE (0.0ms)  SELECT "merchants".* FROM "merchants" WHERE ("merchants"."id" = 2) LIMIT 1

Update: Sorry I am specifically talking about the CACHE lines, do these mean these queries are not run everytime?

CACHE (0.0ms)  SELECT "brands".* FROM "brands" WHERE ("brands"."id" = 408) LIMIT 1
CACHE (0.0ms)  SELECT "categories".* FROM "categories" WHERE ("categories"."id" = 48) LIMIT 1
CACHE (0.0ms)  SELECT "merchants".* FROM "merchants" WHERE ("merchants"."id" = 2) LIMIT 1

Here is the code from the product partial:

<h3><%= product.product_name %></h3>

<img src="<%= product.image %>" align="right" alt="<%= product.product_name %>" height="200" />

<p><%= truncate(product.product_description, :length => 300, :omission => "...") %></p>

<p><%= product.price %></p>

<p>Brand: <%= product.brand.brand_name %></p>

<p>Category: <%= product.category.category_name %></p>

<p>Merchant: <%= product.merchant.merchant_name %></p>

<p><a href="<%= product.link %>" target="_blank">More information</a></p>

<hr />
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T05:20:09+00:00Added an answer on May 20, 2026 at 5:20 am

    You might want to eager load your products/merchants/etc

    @product = Product.find(conditions, :include => {:category, :brand, :merchant})
    

    (I don’t know your relations so use as needed)

    EDIT in regards to your cache question, no those queries aren’t run against the server, but you should definitely look into eager loading so you don’t have unnecessary querying going on

    For more details see the following

    http://rails-bestpractices.com/posts/29-fix-n-1-queries

    http://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html <- See Eager loading

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm doing some Rails stuff with AJAX (not using UJS, but rather rolling my
I'm using Rails 3 and Ruby 1.9.2. I'm doing anything special when I'm displaying
I'm basically just doing some tests to figure out a good way to write
I've just started doing some real-world performance testing on my Fluent NHibernate / SQLite
I am doing some tests, just to learn (normally i do this in ajax
So I'm working on just a learning project to expose myself to doing some
I'm just doing a simple graph using Open Flash Chart http://teethgrinder.co.uk/open-flash-chart/ which shows the
I am doing some plain SQLs in my rails model (for purists this is
HI guys, I am new to rails and just doing my first registration form.
Rails newbie here so just want to be sure I'm doing this right. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.