From 16100ecfe6cf6d7740b45b7126fa60bbe4ab06af Mon Sep 17 00:00:00 2001 From: BrokenEagle Date: Sun, 19 Jan 2020 00:01:32 +0000 Subject: [PATCH] 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. --- app/views/comments/partials/index/_list.html.erb | 4 ++-- app/views/forum_posts/_listing.html.erb | 4 ++-- app/views/users/show.html.erb | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/app/views/comments/partials/index/_list.html.erb b/app/views/comments/partials/index/_list.html.erb index 5bdacd0c0..b9ab4de0e 100644 --- a/app/views/comments/partials/index/_list.html.erb +++ b/app/views/comments/partials/index/_list.html.erb @@ -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? %>
- 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") %>)
<% end %> diff --git a/app/views/forum_posts/_listing.html.erb b/app/views/forum_posts/_listing.html.erb index e6b57147d..7242801a5 100644 --- a/app/views/forum_posts/_listing.html.erb +++ b/app/views/forum_posts/_listing.html.erb @@ -4,10 +4,10 @@ <%- # moderation_reports %>
- <% if CurrentUser.is_moderator? && moderation_reports.any? %> + <% if CurrentUser.is_moderator? && moderation_reports.present? %>
- This topic has forum posts reported for moderation! (<%= moderation_reports.count %> <%= (moderation_reports.count == 1 ? "report" : "reports") %>) + This topic has forum posts reported for moderation! (<%= moderation_reports.length %> <%= (moderation_reports.length == 1 ? "report" : "reports") %>)
<% end %> diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb index 893eba77f..c28a5eae8 100644 --- a/app/views/users/show.html.erb +++ b/app/views/users/show.html.erb @@ -2,10 +2,10 @@

<%= link_to_user @user %>

- <% if !@user.is_moderator? && CurrentUser.is_moderator? && @user.moderation_reports.any? %> + <% if !@user.is_moderator? && CurrentUser.is_moderator? && @user.moderation_reports.present? %>
- This user has been reported for moderation! (<%= @user.moderation_reports.count %> <%= (@user.moderation_reports.count == 1 ? "report" : "reports") %>) + This user has been reported for moderation! (<%= @user.moderation_reports.length %> <%= (@user.moderation_reports.length == 1 ? "report" : "reports") %>)
<% end %>