Fixes an N+1 queries problem in the /moderator/post/queue view by
prefetching disapprovals and uploaders.
Also the way disapproval messages were previously rendered triggered a bunch
of sql queries for each post:
SELECT COUNT(*) FROM "post_disapprovals" WHERE "post_disapprovals"."post_id" = $1 [["post_id", 52]]
SELECT COUNT(*) FROM "post_disapprovals" WHERE "post_disapprovals"."post_id" = $1 AND "post_disapprovals"."reason" = $2 [["post_id", 52], ["reason", "breaks_rules"]]
SELECT COUNT(*) FROM "post_disapprovals" WHERE "post_disapprovals"."post_id" = $1 AND "post_disapprovals"."reason" = $2 [["post_id", 52], ["reason", "poor_quality"]]
SELECT COUNT(*) FROM "post_disapprovals" WHERE "post_disapprovals"."post_id" = $1 AND "post_disapprovals"."reason" IN ('disinterest', 'legacy') [["post_id", 52]]
SELECT COUNT(*) FROM "post_disapprovals" WHERE "post_disapprovals"."post_id" = $1 AND (message is not null and message <> '') [["post_id", 52]]
SELECT "post_disapprovals".* FROM "post_disapprovals" WHERE "post_disapprovals"."post_id" = $1 AND (message is not null and message <> '') [["post_id", 52]]
This refactors to bring it down to one:
SELECT "post_disapprovals".* FROM "post_disapprovals" WHERE "post_disapprovals"."post_id" = $1 [["post_id", 52]]
22 lines
972 B
Plaintext
22 lines
972 B
Plaintext
<% if CurrentUser.can_approve_posts? || post.created_at < 3.days.ago %>
|
|
<p>
|
|
It has been reviewed by <%= pluralize disapprovals.length, "moderator" %>.
|
|
|
|
<% if disapprovals.map(&:reason).grep("breaks_rules").count > 0 %>
|
|
<%= disapprovals.map(&:reason).grep("breaks_rules").count %> believe it breaks the rules.
|
|
<% end %>
|
|
|
|
<% if disapprovals.map(&:reason).grep("poor_quality").count > 0 %>
|
|
<%= disapprovals.map(&:reason).grep("poor_quality").count %> believe it has poor quality.
|
|
<% end %>
|
|
|
|
<% if disapprovals.map(&:reason).grep(/disinterest|legacy/).count > 0 %>
|
|
<%= disapprovals.map(&:reason).grep(/disinterest|legacy/).count %> did not like the post enough to approve it.
|
|
<% end %>
|
|
|
|
<% if disapprovals.map(&:message).any?(&:present?) %>
|
|
Messages: <%= disapprovals.map(&:message).select(&:present?).map { |msg| format_text(msg, ragel: true, inline: true) }.to_sentence.html_safe %>.
|
|
<% end %>
|
|
</p>
|
|
<% end %>
|