Certain parts of comment rendering triggered sql queries that we didn't really need to do. Rework things to avoid this. * Preload comment creators in order to display commenter names with link_to_user. * Preload comment votes in order to display "undo vote" links. Only preload votes for members since anonymous users can't vote and don't have "undo vote" links. * Rework various conditionals to do the filtering in Ruby so that we avoid issuing any extra queries in sql. * Avoid issuing any queries at all when the post doesn't have any comments (when last_commented_at is blank).
28 lines
1.2 KiB
Plaintext
28 lines
1.2 KiB
Plaintext
<div id="p-index-by-post">
|
|
<% if !CurrentUser.user.is_builder? %>
|
|
<div style="margin-bottom: 1em;">
|
|
<h2>Before commenting, read the <%= link_to "how to comment guide", wiki_pages_path(:search => {:title => "howto:comment"}) %>.</h2>
|
|
</div>
|
|
<% end %>
|
|
|
|
<% if @posts.blank? %>
|
|
<%= render "post_sets/blank" %>
|
|
<% end %>
|
|
|
|
<% @posts.select(&:visible?).each do |post| %>
|
|
<% if post.comments.any? { |c| c.visible_by?(CurrentUser.user, show_thresholded: true) } %>
|
|
<%= content_tag(:div, { id: "post_#{post.id}", class: ["post", *PostPresenter.preview_class(post)].join(" ") }.merge(PostPresenter.data_attributes(post))) do %>
|
|
<div class="preview">
|
|
<%= link_to(image_tag(post.preview_file_url), post_path(post)) %>
|
|
</div>
|
|
<%= render "comments/partials/index/list", post: post, comments: post.comments.select { |c| c.visible_by?(CurrentUser.user) }.last(6), page: :comments %>
|
|
<div class="clearfix"></div>
|
|
<% end %>
|
|
<% end %>
|
|
<% end %>
|
|
</div>
|
|
|
|
<%= numbered_paginator(@posts) %>
|
|
|
|
<% content_for(:html_header, auto_discovery_link_tag(:atom, comments_url(:atom, search: { do_not_bump_post: true }), title: "Comments")) %>
|