1

約 1600 行と 4 列の Excel スプレッドシートを使用して、Ruby アプリで表示するデータベースを作成しています。これにより、ページの読み込み時間が 20 秒を超えています。どうすればパフォーマンスを向上させることができますか?

db\seeds.rb から:

oo = Excelx.new("RatingsDB.xlsx")
oo.default_sheet = oo.sheets.first

2.upto(oo.last_row) do |line|
    Rating.create(name: oo.cell(line,'B'), score: oo.cell(line,'C'), when_rated: oo.cell(line,'A'), comment: oo.cell(line,'D'))
end

app\controllers\ratings_controller.rb から:

  def index
    @ratings_by_name = Rating.paginate(:order => 'name ASC', :page => params[:page], :per_page =>10, :conditions => ['name like ?', "%#{params[:search]}%"])
    @ratings_by_score = Rating.paginate(:order => 'score DESC', :page => params[:page], :per_page =>10, :conditions => ['name like ?', "%#{params[:search]}%"])

    respond_to do |format|
      format.html # index.html.erb
      format.json { render json: @ratings_by_name }
    end
  end

app\views\ratings\index.html.erb から:

<div class="tabbable">
  <ul class="nav nav-pills">
    <li class="active"><a href="#tab1" data-toggle="tab">By Name</a></li>
    <li><a href="#tab2" data-toggle="tab">By Score</a></li>
    <li><form class="navbar-search">
      <input type="text" class="search-query span3" placeholder="Search" name="search">
      <div class="icon-search"></div>
     </form></li>
  </ul>

  <div class="tab-content">
    <div class="tab-pane active" id="tab1">
      <% @ratings_by_name.each do |rating| %>
      <div class="rating">
        <div class="row">
          <div class="span7">
            <strong><%= rating.name %></strong>
            <div class="meta">
                | <%= link_to 'View', rating %> | 
              <span class="admin">
                <%= link_to 'Edit', edit_rating_path(rating) %> | 
              </span>
              Rated on <%= rating.when_rated %>
            </div>
          </div>   
          <div class="span1">
            <%= rating.score %>
          </div>
        </div>
      </div>
      <% end %>
      <%= will_paginate @ratings_by_name %>   
    </div>
4

0 に答える 0