我正在研究導軌加速加載時間的技巧。我現在正在處理一個頁面,在渲染時渲染大量數據。我試圖逐步通過每個負載,看看我是否可以優化時間。預加載數據以加快視圖加載時間 - 導軌
我現在的問題是這樣的;
(5.4ms) SELECT COUNT(*) FROM "attendees" WHERE "attendees"."rsvp_id" = $1 [["rsvp_id", 23022]]
(4.4ms) SELECT COUNT(*) FROM "attendees" WHERE "attendees"."rsvp_id" = $1 [["rsvp_id", 23023]]
(4.2ms) SELECT COUNT(*) FROM "attendees" WHERE "attendees"."rsvp_id" = $1 [["rsvp_id", 23024]]
(6.0ms) SELECT COUNT(*) FROM "attendees" WHERE "attendees"."rsvp_id" = $1 [["rsvp_id", 23029]]
(7.1ms) SELECT COUNT(*) FROM "attendees" WHERE "attendees"."rsvp_id" = $1 [["rsvp_id", 23121]]
(6.0ms) SELECT COUNT(*) FROM "attendees" WHERE "attendees"."rsvp_id" = $1 [["rsvp_id", 23180]]
(4.2ms) SELECT COUNT(*) FROM "attendees" WHERE "attendees"."rsvp_id" = $1 [["rsvp_id", 23229]]
(4.2ms) SELECT COUNT(*) FROM "attendees" WHERE "attendees"."rsvp_id" = $1 [["rsvp_id", 23250]]
(6.6ms) SELECT COUNT(*) FROM "attendees" WHERE "attendees"."rsvp_id" = $1 [["rsvp_id", 23254]]
(4.4ms) SELECT COUNT(*) FROM "attendees" WHERE "attendees"."rsvp_id" = $1 [["rsvp_id", 23255]]
(4.0ms) SELECT COUNT(*) FROM "attendees" WHERE "attendees"."rsvp_id" = $1 [["rsvp_id", 23259]]
(6.5ms) SELECT COUNT(*) FROM "attendees" WHERE "attendees"."rsvp_id" = $1 [["rsvp_id", 23154]]
(6.6ms) SELECT COUNT(*) FROM "attendees" WHERE "attendees"."rsvp_id" = $1 [["rsvp_id", 23177]]
(5.1ms) SELECT COUNT(*) FROM "attendees" WHERE "attendees"."rsvp_id" = $1 [["rsvp_id", 23201]]
(4.2ms) SELECT COUNT(*) FROM "attendees" WHERE "attendees"."rsvp_id" = $1 [["rsvp_id", 23221]]
(4.1ms) SELECT COUNT(*) FROM "attendees" WHERE "attendees"."rsvp_id" = $1 [["rsvp_id", 23232]]
(7.9ms) SELECT COUNT(*) FROM "attendees" WHERE "attendees"."rsvp_id" = $1 [["rsvp_id", 23235]]
(4.3ms) SELECT COUNT(*) FROM "attendees" WHERE "attendees"."rsvp_id" = $1 [["rsvp_id", 23237]]
(4.1ms) SELECT COUNT(*) FROM "attendees" WHERE "attendees"."rsvp_id" = $1 [["rsvp_id", 23238]]
(5.9ms) SELECT COUNT(*) FROM "attendees" WHERE "attendees"."rsvp_id" = $1 [["rsvp_id", 23248]]
(7.8ms) SELECT COUNT(*) FROM "attendees" WHERE "attendees"."rsvp_id" = $1 [["rsvp_id", 23295]]
(6.8ms) SELECT COUNT(*) FROM "attendees" WHERE "attendees"."rsvp_id" = $1 [["rsvp_id", 23119]]
(4.2ms) SELECT COUNT(*) FROM "attendees" WHERE "attendees"."rsvp_id" = $1 [["rsvp_id", 23123]]
(4.1ms) SELECT COUNT(*) FROM "attendees" WHERE "attendees"."rsvp_id" = $1 [["rsvp_id", 23178]]
(7.9ms) SELECT COUNT(*) FROM "attendees" WHERE "attendees"."rsvp_id" = $1 [["rsvp_id", 23231]]
(4.4ms) SELECT COUNT(*) FROM "attendees" WHERE "attendees"."rsvp_id" = $1 [["rsvp_id", 23239]]
(4.3ms) SELECT COUNT(*) FROM "attendees" WHERE "attendees"."rsvp_id" = $1 [["rsvp_id", 23240]]
(6.4ms) SELECT COUNT(*) FROM "attendees" WHERE "attendees"."rsvp_id" = $1 [["rsvp_id", 23241]]
(5.1ms) SELECT COUNT(*) FROM "attendees" WHERE "attendees"."rsvp_id" = $1 [["rsvp_id", 23243]]
(6.7ms) SELECT COUNT(*) FROM "attendees" WHERE "attendees"."rsvp_id" = $1 [["rsvp_id", 23245]]
(4.3ms) SELECT COUNT(*) FROM "attendees" WHERE "attendees"."rsvp_id" = $1 [["rsvp_id", 23247]]
(4.2ms) SELECT COUNT(*) FROM "attendees" WHERE "attendees"."rsvp_id" = $1 [["rsvp_id", 23249]]
(6.9ms) SELECT COUNT(*) FROM "attendees" WHERE "attendees"."rsvp_id" = $1 [["rsvp_id", 23251]]
(4.4ms) SELECT COUNT(*) FROM "attendees" WHERE "attendees"."rsvp_id" = $1 [["rsvp_id", 23256]]
(4.2ms) SELECT COUNT(*) FROM "attendees" WHERE "attendees"."rsvp_id" = $1 [["rsvp_id", 23257]]
(6.5ms) SELECT COUNT(*) FROM "attendees" WHERE "attendees"."rsvp_id" = $1 [["rsvp_id", 23275]]
(6.4ms) SELECT COUNT(*) FROM "attendees" WHERE "attendees"."rsvp_id" = $1 [["rsvp_id", 23350]]
(5.0ms) SELECT COUNT(*) FROM "attendees" WHERE "attendees"."rsvp_id" = $1 [["rsvp_id", 23272]]
(4.2ms) SELECT COUNT(*) FROM "attendees" WHERE "attendees"."rsvp_id" = $1 [["rsvp_id", 23296]]
(4.0ms) SELECT COUNT(*) FROM "attendees" WHERE "attendees"."rsvp_id" = $1 [["rsvp_id", 23401]]
(8.8ms) SELECT COUNT(*) FROM "attendees" WHERE "attendees"."rsvp_id" = $1 [["rsvp_id", 23347]]
我越來越從這個代碼:
def number_attending
rsvp.attendees.count
end
所以回函有很多人蔘加。我在這裏調用這個方法。
<% rsvps.each do |rsvp| %>
<span class="event-response__indicator event-response__indicator--guests" title="<%= rsvp.number_attending %> Guests">
<% end %>
所以問題是。我想不必在頁面加載時遍歷每個rsvp和參加者。有沒有預加載數據的方法?像Eagerloading?如果是這樣,我怎麼能用給出的信息來實現它?
我可以知道爲什麼downvote? –