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 6801099
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T19:03:30+00:00 2026-05-26T19:03:30+00:00

The following code always uses more then ten seconds. I have upgraded the server,

  • 0

The following code always uses more then ten seconds. I have upgraded the server, but it doesn’t help. I know I have some database design problems, but I can’t 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.

controller

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'%>")

view

    <%@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> 
  • 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-26T19:03:30+00:00Added an answer on May 26, 2026 at 7:03 pm

    This kind of question is pretty much impossible to answer without seeing all the code involved. Instead I can help you try to figure out where the problem is.

    There are good tools for finding where your performance problems are (e.g. ruby-prof) but if you want a quick primitive way to find where your issue is, just use Time.now. For example, you could change your controller action to be:

    def prods_x_cat
     # This will load all the products of a category
     a1 = Time.now
     @products =  Product.prods_x_cat(params[:id],:include => :raw_datas)
     b1 = Time.now
     p "Time for finding products: #{b1 - a1}"
     a2 = Time.now
     @cortes = RawData.cortes
     b2 = Time.now
     p "Time for finding cortes: #{b2 - a2}"
     respond_to do |format|
       format.js { render :layout=>false}
     end
    end
    

    If the printouts suggest that the time is taken up elsewhere, start doing something similar in your template. Focus on the database calls.

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

Sidebar

Related Questions

I am using following PHP code for trigger creation but always get error, please
The following code doesn't compile with gcc, but does with Visual Studio: template <typename
I have a Lisp (SBCL 1.0.40.0.debian) application (myfitnessdata), which uses the following code to
I have the following code that creates an object in JavaScript. It uses prototype
DataAnnotations does not work with buddy class. The following code always validate true. Why
Following code iterates through many data-rows, calcs some score per row and then sorts
following code doesn't work with input: 2 7 add Elly 0888424242 add Elly 0883666666
The following code works great in IE, but not in FF or Safari. I
The following code illustrates an object literal being assigned, but with no semicolon afterwards:
While debugging a javascript code that uses jQuery I found the following code: [0,

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.