Merge pull request #448 from AyuntamientoMadrid/caches
Cache for comments
This commit is contained in:
@@ -22,4 +22,9 @@ module CacheKeysHelper
|
||||
user_status
|
||||
end
|
||||
|
||||
# when commentable id and type are used but no need to update cache on updated_at changes
|
||||
def commentable_cache_key(commentable)
|
||||
"#{commentable.class.name}-#{commentable.id}"
|
||||
end
|
||||
|
||||
end
|
||||
@@ -2,7 +2,7 @@ class Comment < ActiveRecord::Base
|
||||
acts_as_paranoid column: :hidden_at
|
||||
include ActsAsParanoidAliases
|
||||
acts_as_votable
|
||||
has_ancestry
|
||||
has_ancestry touch: true
|
||||
|
||||
attr_accessor :as_moderator, :as_administrator
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
<% cache [locale_and_user_status(comment), comment, commentable_cache_key(@commentable), comment.author, (@comment_flags[comment.id] if @comment_flags)] do %>
|
||||
<div class="row">
|
||||
<div id="<%= dom_id(comment) %>" class="comment small-12 column">
|
||||
|
||||
@@ -58,7 +59,7 @@
|
||||
|
||||
<% end %>
|
||||
|
||||
• <%= time_ago_in_words(comment.created_at) %>
|
||||
• <time><%= l comment.created_at.to_datetime, format: :datetime %></time>
|
||||
</div>
|
||||
|
||||
<% if comment.as_administrator? %>
|
||||
@@ -100,3 +101,4 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
@@ -1,3 +1,4 @@
|
||||
<% cache [locale_and_user_status, parent_id, commentable_cache_key(commentable)] do %>
|
||||
<% css_id = parent_or_commentable_dom_id(parent_id, commentable) %>
|
||||
<div id="js-comment-form-<%= css_id %>" <%= "style='display:none'".html_safe if toggeable %>>
|
||||
<%= form_for [commentable, Comment.new], remote: true do |f| %>
|
||||
@@ -24,3 +25,4 @@
|
||||
|
||||
<% end %>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<% cache [locale_and_user_status, commentable_cache_key(@debate), @all_visible_comments, @all_visible_comments.map(&:author), @debate.comments_count, @comment_flags] 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>
|
||||
@@ -26,3 +26,4 @@
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
<% end %>
|
||||
@@ -20,3 +20,6 @@
|
||||
# available at http://guides.rubyonrails.org/i18n.html.
|
||||
|
||||
en:
|
||||
time:
|
||||
formats:
|
||||
datetime: "%Y-%m-%d %H:%M:%S"
|
||||
|
||||
@@ -196,4 +196,5 @@ es:
|
||||
default: "%A, %d de %B de %Y %H:%M:%S %z"
|
||||
long: "%d de %B de %Y %H:%M"
|
||||
short: "%d de %b %H:%M"
|
||||
datetime: "%d/%m/%Y %H:%M:%S"
|
||||
pm: pm
|
||||
@@ -14,7 +14,7 @@ feature 'Comments' do
|
||||
comment = Comment.last
|
||||
within first('.comment') do
|
||||
expect(page).to have_content comment.user.name
|
||||
expect(page).to have_content time_ago_in_words(comment.created_at)
|
||||
expect(page).to have_content I18n.l(comment.created_at, format: :datetime)
|
||||
expect(page).to have_content comment.body
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user