Use better method of querying the moderation reports for an instance

The use of any? and count was forcing new SQL requests for each statement.
Instead, present? and length were used which act on the reports once loaded.
Although unneeded, the comment and forum views were changed as well for consistency.
This commit is contained in:
BrokenEagle
2020-01-19 00:01:32 +00:00
parent f3ce811def
commit 16100ecfe6
3 changed files with 6 additions and 6 deletions

View File

@@ -3,10 +3,10 @@
<%= render "comments/partials/index/header", :post => post %>
<% end %>
<% if CurrentUser.is_moderator? && post.moderation_reports.any? %>
<% if CurrentUser.is_moderator? && post.moderation_reports.present? %>
<div class="row moderation-comments-notice">
<span class="info" id="moderation-comments-notice-for-<%= post.id %>">
This post has comments reported for moderation! (<%= post.moderation_reports.count %> <%= (post.moderation_reports.count == 1 ? "report" : "reports") %>)
This post has comments reported for moderation! (<%= post.moderation_reports.length %> <%= (post.moderation_reports.length == 1 ? "report" : "reports") %>)
</span>
</div>
<% end %>