From bf18da3faa4099815758336a6b8e48863c52ea02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juanjo=20Baz=C3=A1n?= Date: Sun, 6 Sep 2015 22:03:31 +0200 Subject: [PATCH] adds cache for authors of debate/comment --- app/helpers/cache_keys_helper.rb | 7 ++++--- app/views/comments/_comment.html.erb | 2 +- app/views/debates/show.html.erb | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/app/helpers/cache_keys_helper.rb b/app/helpers/cache_keys_helper.rb index f75a21a59..6bcd8ca91 100644 --- a/app/helpers/cache_keys_helper.rb +++ b/app/helpers/cache_keys_helper.rb @@ -1,11 +1,11 @@ module CacheKeysHelper - def locale_and_user_status - @cache_key_user ||= calculate_user_status + def locale_and_user_status(authorable=nil) + @cache_key_user ||= calculate_user_status(authorable) "#{I18n.locale}/#{@cache_key_user}" end - def calculate_user_status + def calculate_user_status(authorable=nil) user_status = "user" if user_signed_in? @@ -14,6 +14,7 @@ module CacheKeysHelper user_status += ":org" if current_user.organization? user_status += ":admin" if current_user.administrator? user_status += ":moderator" if current_user.moderator? + user_status += ":author" if authorable && authorable.author == current_user else user_status += ":visitor" end diff --git a/app/views/comments/_comment.html.erb b/app/views/comments/_comment.html.erb index a84aebb63..739c3d4c8 100644 --- a/app/views/comments/_comment.html.erb +++ b/app/views/comments/_comment.html.erb @@ -1,4 +1,4 @@ -<% cache [locale_and_user_status, comment, @commentable, comment.author, (@comment_flags[comment.id] if @comment_flags)] do %> +<% cache [locale_and_user_status(comment), comment, @commentable, comment.author, (@comment_flags[comment.id] if @comment_flags)] do %>
diff --git a/app/views/debates/show.html.erb b/app/views/debates/show.html.erb index 07f7504cf..28d514817 100644 --- a/app/views/debates/show.html.erb +++ b/app/views/debates/show.html.erb @@ -1,4 +1,4 @@ -<% cache [locale_and_user_status, @debate, @debate.author, Flag.flagged?(current_user, @debate)] do %> +<% cache [locale_and_user_status(@debate), @debate, @debate.author, Flag.flagged?(current_user, @debate)] do %>