Changes: * Drop Users.id_to_name. * Don't cache Users.name_to_id. * Replace calls to name_to_id with find_by_name when possible. * Don't autodefine creator_name in belongs_to_creator. * Don't autodefine updater_name in belongs_to_updater. * Instead manually define creator_name / updater_name only on models that need to return these fields in the api. id_to_name was cached to reduce the impact of N+1 query patterns in certain places, especially in api responses that return creator_name / updater_name fields. But it still meant we were doing N calls to memcache. Using `includes` to prefetch users avoids this N+1 pattern. name_to_id had no need be cached, it was never used in any performance- sensitive contexts. Avoiding caching also avoids the need to keep these caches consistent.
54 lines
2.8 KiB
Plaintext
54 lines
2.8 KiB
Plaintext
<% if CurrentUser.is_moderator? || (params[:search] && params[:search][:is_deleted] =~ /t/) || !comment.is_deleted? %>
|
|
<a name="comment-<%= comment.id %>"></a>
|
|
<article class="comment <%= "below-threshold" if comment.below_threshold? %>" data-post-id="<%= comment.post_id %>" data-comment-id="<%= comment.id %>" data-score="<%= comment.score %>" data-creator="<%= comment.creator.name %>" data-is-sticky="<%= comment.is_sticky %>">
|
|
<div class="author">
|
|
<h1>
|
|
<%= link_to_user comment.creator %>
|
|
<% if comment.is_deleted? %>
|
|
(deleted)
|
|
<% end %>
|
|
</h1>
|
|
<p>
|
|
<%= time_ago_in_words_tagged(comment.created_at) %>
|
|
</p>
|
|
</div>
|
|
<div class="content">
|
|
<div class="body prose">
|
|
<%= format_text(comment.body) %>
|
|
|
|
<%= render "application/update_notice", record: comment %>
|
|
</div>
|
|
|
|
<% if CurrentUser.is_member? %>
|
|
<menu>
|
|
<% if @post || @posts %>
|
|
<li><%= link_to "Reply", new_comment_path(id: comment, comment: { post_id: comment.post_id }), class: "reply-link", remote: true %></li>
|
|
<% if comment.editable_by?(CurrentUser.user) %>
|
|
<% if comment.is_deleted? %>
|
|
<li><%= link_to "Undelete", undelete_comment_path(comment.id), :method => :post, :remote => true %></li>
|
|
<% else %>
|
|
<li><%= link_to "Delete", comment_path(comment.id), :data => {:confirm => "Are you sure you want to delete this comment?"}, :method => :delete, :remote => true %></li>
|
|
<% end %>
|
|
<li><%= link_to "Edit", edit_comment_path(comment.id), :id => "edit_comment_link_#{comment.id}", :class => "edit_comment_link" %></li>
|
|
<% end %>
|
|
<li id="comment-vote-up-link-for-<%= comment.id %>"><%= link_to "Vote up", comment_votes_path(:comment_id => comment.id, :score => "up"), :method => :post, :remote => true %></li>
|
|
<li id="comment-vote-down-link-for-<%= comment.id %>"><%= link_to "Vote down", comment_votes_path(:comment_id => comment.id, :score => "down"), :method => :post, :remote => true %></li>
|
|
<li style="display: none;" id="comment-unvote-link-for-<%= comment.id %>" class="unvote-comment-link"><%= link_to "Unvote", comment_votes_path(:comment_id => comment.id), :method => :delete, :remote => true %></li>
|
|
<% if CurrentUser.is_moderator? %>
|
|
<li>|</li>
|
|
<li>
|
|
<strong>IP</strong>
|
|
<span><%= link_to_ip comment.creator_ip_addr %></span>
|
|
</li>
|
|
<% end %>
|
|
<% end %>
|
|
</menu>
|
|
<% if comment.editable_by?(CurrentUser.user) %>
|
|
<%= render "comments/form", comment: comment, hidden: true %>
|
|
<% end %>
|
|
<% end %>
|
|
</div>
|
|
<div class="clearfix"></div>
|
|
</article>
|
|
<% end %>
|