2017-04-19 13 views
0

ロード時間を短縮するための手法について検討しています。私は今レンダリング時に大量のデータをレンダリングしているページで作業しています。私は各負荷をステップアップして、時間を最適化できるかどうかを確認しようとしています。ロード時間を短縮するためにデータをプリロードする - レール

私が現在持っている問題はこれです。

(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のようなもの?もしそうなら、私はどのように情報を与えて実装することができますか?

答えて

0

チェックアウトthis link、 これは、カウントのn + 1クエリを避けるためのものです。

これは、結合クエリを実行するか、同じもののビューを作成することを説明します

-1

あなたはrsvpsのクエリ方法を示していないので、rsvps = Rsvp.allと見なします。 includesメソッドを追加するだけで、rsvps = Rsvp.includes(:attendees).allのようになります。

また、私はこの行を実行しているときにクエリを避けるかどうかわかりませんrsvp.attendees.countcountメソッドでクエリがトリガーされたが、sizeメソッドでは発生しなかった状況が発生したため、この行をrsvp.attendees.sizeに置き換える必要があります。

+0

なぜdownvoteを知ることができますか? –

関連する問題