forum_topics/show: fix N+1 query patterns.

This commit is contained in:
evazion
2020-02-05 18:05:56 -06:00
parent db4c67ee86
commit 69f653b0c4
6 changed files with 6 additions and 22 deletions

View File

@@ -11,6 +11,6 @@
<%= render "forum_post_votes/vote", vote: vote, forum_post: forum_post %>
<% end %>
<% if forum_post.tag_change_request && forum_post.tag_change_request.is_pending? && !votes.by(CurrentUser.user.id).exists? %>
<% if forum_post.votable? && !votes.by(CurrentUser.user.id).exists? %>
<%= render "forum_post_votes/add_vote", vote: votes.by(CurrentUser.user.id).first, forum_post: forum_post %>
<% end %>

View File

@@ -4,7 +4,7 @@
%>
<li class="vote-score-<%= vote.vote_type %>">
<% if forum_post.tag_change_request && forum_post.tag_change_request.is_pending? && vote.creator_id == CurrentUser.id %>
<% if forum_post.votable? && vote.creator_id == CurrentUser.id %>
<%= link_to content_tag(:i, nil, class: "far #{vote.fa_class}"), forum_post_vote_path(vote, format: "js"), remote: true, method: :delete %>
<%= link_to_user vote.creator %>
<% else %>

View File

@@ -40,7 +40,7 @@
<% if forum_post.reportable_by?(CurrentUser.user) %>
<li><%= link_to "Report", new_moderation_report_path(moderation_report: { model_type: "ForumPost", model_id: forum_post.id }), remote: true, title: "Report this forum post to the moderators" %></li>
<% end %>
<% if forum_post.votable? %>
<% if forum_post.bulk_update_request.present? %>
<ul class="votes" id="forum-post-votes-for-<%= forum_post.id %>">
<%= render "forum_post_votes/list", votes: forum_post.votes, forum_post: forum_post %>
</ul>