1
我正在使用Rails 3.0.7,kaminari寶石。頁面索引需要太多時間來加載
我剛剛建立了一個簡單的網站,使用SQLite數據庫和數據的100,000行,只有四列(ID
,name
,created_at
,updated_at
)。
這是我的控制器:
class HclinksController < ApplicationController
# GET /hclinks
# GET /hclinks.xml
def index
@hclinks = Hclink.page(params[:page])
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @hclinks }
end
end
end
我腳手架它。
這裏是我的日誌:
// THIS IS INDEX, WHICH SHOWS ALL THE LIST ITEMS
Started GET "/hclinks" for 127.0.0.1 at 2011-05-08 00:59:52 +0800
Processing by HclinksController#index as HTML
Hclink Load (391.8ms) SELECT "hclinks".* FROM "hclinks" LIMIT 25 OFFSET 0
SQL (4574.8ms) SELECT COUNT(*) FROM "hclinks"
Rendered hclinks/index.html.erb within layouts/application (178778.1ms)
Completed 200 OK in 182775ms (Views: 175845.5ms | ActiveRecord: 4966.6ms)
// THIS IS THE RUBY ON RAILS WELCOME PAGE
Started GET "/hclinks" for 127.0.0.1 at 2011-05-08 01:03:13 +0800
Processing by HclinksController#index as HTML
Hclink Load (65.3ms) SELECT "hclinks".* FROM "hclinks" LIMIT 25 OFFSET 0
SQL (910.6ms) SELECT COUNT(*) FROM "hclinks"
Rendered hclinks/index.html.erb within layouts/application (1532.2ms)
Completed 200 OK in 1657ms (Views: 652.5ms | ActiveRecord: 975.9ms)
我不知道爲什麼名單了這麼久纔回應...我應該怎麼解決呢?謝謝!
時間主要花在視圖上。你是否在索引頁面的循環中使用partials?在開發模式下,這可能會在較慢的機器上花費很多時間。 – Thilo 2011-05-10 13:44:58
該視圖很簡單,只是一個「ol」列表。沒有偏見。 – Victor 2011-05-11 02:03:21