【发布时间】:2011-11-04 19:26:47
【问题描述】:
以下代码总是使用十秒以上。我已经升级了服务器,但它没有帮助。我知道我有一些数据库设计问题,但我无法修改。
我正在显示同一类别产品的不同位置的所有价格也在不同的时间范围内,因为每个位置的价格每 15 天变化一次。
控制器
def prods_x_cat
# This will load all the products of a category
@products = Product.prods_x_cat(params[:id],:include => :raw_datas)
@cortes = RawData.cortes
respond_to do |format|
format.js { render :layout=>false}
end
end
prods_x_cat.js.erb
var jqxhr1 = $.ajax($("#loading_overlay .loading_message, #loading_overlay").fadeIn());
$('#datos').html("<%= escape_javascript render :partial=>'/shared/prods_x_cat'%>")
查看
<%@cortes.each do |c|%>
<a href="#<%=c.corte%>" class="round_top"><%=c.corte%></a>
<%end%>
<%@cortes.each do |c|%>
<%@fecha = c.corte_real%>
<div id="<%=c.corte%>" class="block no_padding">
<table class="display datatable">
<thead>
<tr>
<th>SKU</th>
<%Company.active.order('table_field ASC').each do |c|%>
<th><%=c.abbr%></th>
<%end%>
<th>Average</th>
<th>Mode</th>
<th>Minimum</th>
<th>Maximum</th>
</tr>
</thead>
<tbody>
<%@products.each do |p|%>
<tr class="gradeA">
<td><%=p.name%></td>
<%p.raw_datas.where("product_id='#{p.id}' and corte_real='#{@fecha}'").each do |prd|%>
<td><%=prd.location1.to_f.round(2)%></td>
<td><%=prd.location2.to_f.round(2)%></td>
<td><%=prd.location3.to_f.round(2)%></td>
<td><%=prd.location4.to_f.round(2)%></td>
<td><%=prd.location5.to_f.round(2)%></td>
<td><%=prd.location6.to_f.round(2)%></td>
<td><%=prd.location7.to_f.round(2)%></td>
<td><%=prd.location8.to_f.round(2)%></td>
<td><%=prd.promedio.to_f.round(2)%></td>
<td><%=prd.moda%></td>
<td><%=prd.minimo.to_f.round(2)%></td>
<td><%=prd.maximo.to_f.round(2)%></td>
<%end%>
</tr>
<%end%>
</tbody>
</table>
</div>
<%end%>
</div>
【问题讨论】:
标签: ruby-on-rails ruby-on-rails-3 activerecord ruby-on-rails-3.1