Merge pull request #374 from AyuntamientoMadrid/cache-refactor
Cache refactor
This commit is contained in:
@@ -36,17 +36,6 @@ class User < ActiveRecord::Base
|
||||
scope :officials, -> { where("official_level > 0") }
|
||||
scope :for_render, -> { includes(:organization) }
|
||||
|
||||
after_update :touch_debates, :touch_comments
|
||||
after_touch :touch_debates, :touch_comments
|
||||
|
||||
def touch_debates
|
||||
debates.map(&:touch)
|
||||
end
|
||||
|
||||
def touch_comments
|
||||
comments.map(&:touch)
|
||||
end
|
||||
|
||||
def self.find_for_oauth(auth, signed_in_resource = nil)
|
||||
# Get the identity and user if they exist
|
||||
identity = Identity.find_for_oauth(auth)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<% cache [locale_and_user_status, comment, @commentable, Flag.flagged?(current_user, comment)] do %>
|
||||
<% cache [locale_and_user_status, comment, @commentable, comment.author, (@comment_flags[comment.id] if @comment_flags)] do %>
|
||||
<div class="row">
|
||||
<div id="<%= dom_id(comment) %>" class="comment small-12 column">
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<% cache [locale_and_user_status, @all_visible_comments.map(&:cache_key), @debate.comments_count, @comment_flags.to_a] do %>
|
||||
<% cache [locale_and_user_status, @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">
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<% cache [locale_and_user_status, @debate, Flag.flagged?(current_user, @debate)] do %>
|
||||
<% cache [locale_and_user_status, @debate, @debate.author, Flag.flagged?(current_user, @debate)] do %>
|
||||
<section class="debate-show">
|
||||
<div id="<%= dom_id(@debate) %>" class="row">
|
||||
<div class="small-12 medium-9 column">
|
||||
|
||||
@@ -52,18 +52,18 @@ describe Comment do
|
||||
|
||||
it "should expire cache when the author is hidden" do
|
||||
expect { comment.user.hide }
|
||||
.to change { comment.reload.updated_at }
|
||||
.to change { [comment.reload.updated_at, comment.author.updated_at] }
|
||||
end
|
||||
|
||||
it "should expire cache when the author changes" do
|
||||
expect { comment.user.update(username: "Isabel") }
|
||||
.to change { comment.reload.updated_at }
|
||||
.to change { [comment.reload.updated_at, comment.author.updated_at] }
|
||||
end
|
||||
|
||||
it "should expire cache when the author's organization get verified" do
|
||||
create(:organization, user: comment.user)
|
||||
expect { comment.user.organization.verify }
|
||||
.to change { comment.reload.updated_at}
|
||||
.to change { [comment.reload.updated_at, comment.author.updated_at] }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -286,15 +286,25 @@ describe Debate do
|
||||
.to change { debate.updated_at }
|
||||
end
|
||||
|
||||
it "should expire cache when hidden" do
|
||||
expect { debate.hide }
|
||||
.to change { debate.updated_at }
|
||||
end
|
||||
|
||||
it "should expire cache when the author is hidden" do
|
||||
expect { debate.author.hide }
|
||||
.to change { [debate.reload.updated_at, debate.author.updated_at] }
|
||||
end
|
||||
|
||||
it "should expire cache when its author changes" do
|
||||
expect { debate.author.update(username: "Eva") }
|
||||
.to change { debate.reload.updated_at }
|
||||
.to change { [debate.reload.updated_at, debate.author.updated_at] }
|
||||
end
|
||||
|
||||
it "should expire cache when the author's organization get verified" do
|
||||
create(:organization, user: debate.author)
|
||||
expect { debate.author.organization.verify }
|
||||
.to change { debate.reload.updated_at}
|
||||
.to change { [debate.reload.updated_at, debate.author.updated_at] }
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user