From 040f7d1e1de54b0b63e90fb93b3b0debe7af337f Mon Sep 17 00:00:00 2001 From: Rodrigo Souto Date: Wed, 24 Oct 2012 17:11:02 +0000 Subject: [PATCH] Sweeping cache of article new parent and previous parent when article is moved --- app/sweepers/article_sweeper.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/app/sweepers/article_sweeper.rb b/app/sweepers/article_sweeper.rb index a984b7d..cc1f600 100644 --- a/app/sweepers/article_sweeper.rb +++ b/app/sweepers/article_sweeper.rb @@ -10,10 +10,16 @@ class ArticleSweeper < ActiveRecord::Observer expire_caches(article) end + def before_update(article) + if article.parent_id_change + Article.find(article.parent_id_was).touch if article.parent_id_was + end + end + protected def expire_caches(article) - article.hierarchy.each { |a| a.touch if a != article } + article.hierarchy(true).each { |a| a.touch if a != article } blocks = article.profile.blocks blocks += article.profile.environment.blocks if article.profile.environment blocks = blocks.select{|b|[RecentDocumentsBlock, BlogArchivesBlock].any?{|c| b.kind_of?(c)}} -- libgit2 0.21.2