PERF: fix N+1 queries for non-JS topic view.

PERF: fix N+1 queries for non-JS topic view.

diff --git a/app/views/topics/show.html.erb b/app/views/topics/show.html.erb
index 5e8ce1a..9d921c5 100644
--- a/app/views/topics/show.html.erb
+++ b/app/views/topics/show.html.erb
@@ -46,7 +46,8 @@
           <a itemprop="url" href='<%= Discourse.base_uri %>/u/<%= u.username %>'><span itemprop='name'><%= u.username %></span></a>
           <%= "(#{u.name})" if (SiteSetting.display_name_on_posts && SiteSetting.enable_names? && !u.name.blank?) %>
           <%
-            who_username = post.custom_fields["action_code_who"] || ""
+            post_custom_fields = @topic_view.post_custom_fields[post.id] || {}
+            who_username = post_custom_fields["action_code_who"] || ""
             if post.action_code
           %>
             <%= t("js.action_codes.#{post.action_code}", when: "", who: who_username).html_safe %>

GitHub sha: f9f12ed2

1 Like