PERF: Avoid calling the same translation twice when rendering lists view (#22976)

Why this change?

In production, this appeared as a small hotspot as where we're calling
`poster.name_and_description` twice which in turns makes a method call
to `I18n.t`. When we're rendering a topic list with many topics and each
topic has many posters, this repeated and unnecessary method call
quickly adds up.
This commit is contained in:
Alan Guo Xiang Tan 2023-08-04 13:38:41 +08:00 committed by GitHub
parent 1f7e5e8e75
commit 5d1a9a44c6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -88,7 +88,8 @@
<td class='posters'>
<% t.posters.each do |poster| %>
<a href="<%= Discourse.base_url %>/u/<%= poster.user.username %>" class="<%= poster.extras %>">
<img width="25" height="25" src="<%= poster.user.avatar_template.gsub('{size}', '25') %>" class="avatar" title='<%= h(poster.name_and_description) %>' aria-label='<%= h(poster.name_and_description) %>'>
<%- poster_name_and_description = h(poster.name_and_description) %>
<img width="25" height="25" src="<%= poster.user.avatar_template.gsub('{size}', '25') %>" class="avatar" title='<%= poster_name_and_description %>' aria-label='<%= poster_name_and_description %>'>
</a>
<% end %>
</td>