I'm working on a Rails app that can have 20-30k records for a single query that will render on a page. I'd appreciate some feedback on this query thanks!
The Controller
def index
if params[:advertiser].blank?
@products = Product.all
else
@advertiser_name = Advertiser.find_by(name: params[:advertiser]).name
@products = Product.where(advertiser: @advertiser_name)
end
end
The Product object has all the records and can be looked up by advertiser name.
The View
<div class="product-listing">
<ul>
<% @products.each do |p| %>
<li id="name">Product Name: <%= p.product_name %></li>
<li id="advertiser">Advertiser: <%= p.advertiser %></li>
<li id="designer">Designer: <%= p.designer %></li>
<li id="price">Price: <%= p.price %></li>
<li id="commission">Commission: <%= p.commission %></li>
<li id="url">Url: <%= p.product_url %></li>
<hr>
<% end %>
</ul>
</div>
Current Load time
Completed 200 OK in 35531ms (Views: 31808.9ms | ActiveRecord: 3689.6ms)
It would probably help to show you guys my Schema.
ActiveRecord::Schema.define(version: 20151227085753) do
create_table "advertisers", force: :cascade do |t|
t.string "name"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
create_table "products", force: :cascade do |t|
t.string "product_id"
t.string "product_name"
t.string "product_url"
t.string "advertiser"
t.string "designer"
t.string "price"
t.string "commission"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
add_index "products", ["advertiser"], name: "index_products_on_advertiser"
end