bulletでn+1問題修正しているのですが1箇所だけどうしても修正することができません
ブログのコメント機能ようなロジック部分なのですが
別のユーザーが書き込むとn+1が発生します。
bulletログは下記の通りです。
N+1 Query detected
User => [:profile]
Add to your finder: :includes => [:profile]
N+1 Query method call stack
/Users/kita/Documents/ponta-ver3.0.0/app/views/items/show.html.erb:115:in block in _app_views_items_show_html_erb__4048271209300901525_70100707361500' /Users/kita/Documents/ponta-ver3.0.0/app/views/items/show.html.erb:109:in
_app_views_items_show_html_erb__4048271209300901525_70100707361500'
アソシエーション
Item model
has_many :comments, dependent: :destroy
Commnt model
belongs_to :item
lang
1#Item Controller 2 3def show 4 @comments = @item.comments.includes(:user).order(:created_at) 5end 6
lang
1#Comment Controller 2 def create 3 comment = current_user.comments.build do |t| 4 t.item_id = params[:item_id] 5 t.body = params[:comment][:body] 6 end 7 8 if comment.save 9 flash[:notice] = 'コメントしました。' 10 head 201 11 else 12 render json: { messages: comment.errors.full_messages }, status: 422 13 end 14 end 15 16 17#html.erb 18 19#115行目 20<% if comment.user.profile.picture_1.present? %> 21 <%= link_to image_tag(comment.user.profile.picture_1_url, width: 90, class:"img-circle img-responsive" ) , profile_path(comment.user_id) %> 22 <% else%> 23 <%= link_to image_tag('opps.jpg', class:"img-circle img-responsive"), profile_path(comment.user_id)%> 24 <% end%>
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2015/03/27 22:44