例如,我叫了三諧音在我的食譜/ _cuisines.html.erb文件:Ruby on Rails:爲什麼在我的視圖中調用局部渲染會花費很長時間?
<%= render "recipes/cuisines/denmark.html %>
<%= render "recipes/cuisines/spain.html %>
<%= render "recipes/cuisines/italy.html %>
東西都不是在該文件中。部分只是靜態內容,沒有集合。這是我從我的日誌中獲取:
Rendered recipes/cuisines/_denmark.html.erb (4.6ms) [cache miss]
Rendered recipes/cuisines/_spain.html.erb (2.3ms) [cache miss]
Rendered recipes/cuisines/_italy.html.erb (5.3ms) [cache miss]
Rendered recipes/_cuisines.html.erb (161.5ms) [cache miss]
如果我刪除諧音之一,我得到的是這樣的:
Rendered recipes/cuisines/_denmark.html.erb (4.6ms) [cache miss]
Rendered recipes/cuisines/_spain.html.erb (2.3ms) [cache miss]
Rendered recipes/_cuisines.html.erb (101.7ms) [cache miss]
取出另一部分,我得到:
Rendered recipes/cuisines/_denmark.html.erb (4.6ms) [cache miss]
Rendered recipes/_cuisines.html.erb (50.5ms) [cache miss]
刪除每一個部分,我得到這樣的事情:
Rendered recipes/_cuisines.html.erb (0.9ms) [cache miss]
看來,它需要一個非常時期,從而使得各部分即使部分本身是非常小的。你知道是什麼原因導致的,我能做些什麼來更快地調用偏好函數?建議不要叫部分嗎?
(我用Rails 5.1.1和Ruby 2.5.0dev)
我不知道它會如此簡單:)非常感謝普拉莫德! – sjsc