caches comments

This commit is contained in:
rgarcia
2015-09-05 21:54:14 +02:00
parent 93378eea98
commit 5200d76be6
3 changed files with 141 additions and 105 deletions

View File

@@ -1,4 +1,5 @@
<div class="row">
<% cache [locale_and_user_status, comment, @commentable, Flag.flagged?(current_user, comment)] do %>
<div class="row">
<div id="<%= dom_id(comment) %>" class="comment small-12 column">
<% if comment.hidden? || comment.user.hidden? %>
@@ -93,9 +94,11 @@
</div>
</div>
<% end %>
<% end %>
<div class="comment-children">
<%= render select_children(@comments, comment) if @comments.present? %>
<% select_children(@comments, comment).each do |child| %>
<%= render 'comments/comment', comment: child %>
<% end %>
</div>
</div>
</div>

View File

@@ -1,5 +1,6 @@
<% css_id = parent_or_commentable_dom_id(parent_id, commentable) %>
<div id="js-comment-form-<%= css_id %>" <%= "style='display:none'".html_safe if toggeable %>>
<% cache [locale_and_user_status, css_id] do %>
<div id="js-comment-form-<%= css_id %>" <%= "style='display:none'".html_safe if toggeable %>>
<%= form_for [commentable, Comment.new], remote: true do |f| %>
<%= label_tag "comment-body-#{css_id}", t("comments.form.leave_comment") %>
<%= f.text_area :body, id: "comment-body-#{css_id}", label: false %>
@@ -21,5 +22,7 @@
<%= label_tag "comment-as-administrator-#{css_id}", t("comments.form.comment_as_admin"), class: "checkbox" %>
</div>
<% end %>
<% end %>
</div>
</div>
<% end %>

View File

@@ -0,0 +1,30 @@
<% cache [locale_and_user_status, @all_visible_comments.map(&:cache_key), @debate.comments_count, @comment_flags.to_a] do %>
<section class="row-full comments">
<div class="row">
<div id="comments" class="small-12 column">
<h2>
<%= t("debates.show.comments_title") %>
<span>(<%= @debate.comments_count %>)</span>
</h2>
<% if user_signed_in? %>
<%= render 'comments/form', {commentable: @debate, parent_id: nil, toggeable: false} %>
<% else %>
<br>
<div class="alert-box radius info">
<%= t("debates.show.login_to_comment",
signin: link_to(t("votes.signin"), new_user_session_path),
signup: link_to(t("votes.signup"), new_user_registration_path)).html_safe %>
</div>
<% end %>
<% @root_comments.each do |comment| %>
<%= render 'comments/comment', comment: comment %>
<% end %>
<%= paginate @root_comments %>
</div>
</div>
</section>
<% end %>