Low performance

i dealing with this code, but i always getting more than 10 seconds to
load, i even upgraded the server, but is the same… i know i have some
database design problem, but i cant modify that.

i am showing all the prices from differents locations of products of a
category also in different time range, because the prices change every
15 days in each location.


def prods_x_cat
 # This will load all the products of a category
 @products =  Product.prods_x_cat(params[:id],:include =>

@cortes = RawData.cortes
respond_to do |format|
format.js { render :layout=>false}


 var jqxhr1 = $.ajax($("#loading_overlay .loading_message,

$(’#datos’).html("<%= escape_javascript render


    <[email protected] do |c|%>
<a href="#<%=c.corte%>" class="round_top"><%=c.corte%></a>
    <[email protected] do |c|%>
     <%@fecha = c.corte_real%>
     <div id="<%=c.corte%>" class="block no_padding">
     <table class="display datatable">
            <%Company.active.order('table_field ASC').each do |c|%>
    <[email protected] do |p|%>
     <tr class="gradeA">
    <%p.raw_datas.where("product_id='#{p.id}' and

corte_real=’#{@fecha}’").each do |prd|%>




i know it should be something with the query, still don’t know

  1. are you sure all foreign keys are indexed
  2. could you also post table structures and queries generated, it
    might help to understand the problem