Commit c3e49384d093b7a1fd5aef261b02395c5680ec8b

Authored by Daniela Feitosa
1 parent 2abc4514

Removed whitespaces

Also allowing the expire of cache from old layouts
app/helpers/sweeper_helper.rb
... ... @@ -44,7 +44,7 @@ module SweeperHelper
44 44 def expire_profile_index(profile)
45 45 expire_timeout_fragment(profile.relationships_cache_key)
46 46 end
47   -
  47 +
48 48 def expire_blocks_cache(context, causes)
49 49 if context.kind_of?(Profile)
50 50 profile = context
... ... @@ -53,7 +53,7 @@ module SweeperHelper
53 53 environment = context
54 54 profile = nil
55 55 end
56   -
  56 +
57 57 blocks_to_expire = []
58 58 if profile
59 59 profile.blocks.each {|block|
... ... @@ -65,9 +65,9 @@ module SweeperHelper
65 65 conditions = block.class.expire_on
66 66 blocks_to_expire << block unless (conditions[:environment] & causes).empty?
67 67 }
68   -
  68 +
69 69 blocks_to_expire.uniq!
70 70 BlockSweeper.expire_blocks(blocks_to_expire)
71   - end
72   -
  71 + end
  72 +
73 73 end
... ...
app/models/article_block.rb
... ... @@ -23,7 +23,7 @@ class ArticleBlock &lt; Block
23 23 def article_id
24 24 self.settings[:article_id]
25 25 end
26   -
  26 +
27 27 def article_id= value
28 28 self.settings[:article_id] = value.blank? ? nil : value.to_i
29 29 end
... ... @@ -63,7 +63,7 @@ class ArticleBlock &lt; Block
63 63 end
64 64  
65 65 settings_items :visualization_format, :type => :string, :default => 'short'
66   -
  66 +
67 67 def self.expire_on
68 68 { :profile => [:article], :environment => [:article] }
69 69 end
... ...
app/models/block.rb
... ... @@ -133,7 +133,7 @@ class Block &lt; ActiveRecord::Base
133 133 def cache_key(language='en')
134 134 active_record_cache_key+'-'+language
135 135 end
136   -
  136 +
137 137 def timeout
138 138 4.hours
139 139 end
... ... @@ -145,7 +145,7 @@ class Block &lt; ActiveRecord::Base
145 145 # Override in your subclasses.
146 146 # Define which events and context should cause the block cache to expire
147 147 # Possible events are: :article, :profile, :friendship, :category
148   - # Possible contexts are: :profile, :environment
  148 + # Possible contexts are: :profile, :environment
149 149 def self.expire_on
150 150 {
151 151 :profile => [],
... ...
app/sweepers/article_sweeper.rb
... ... @@ -15,15 +15,15 @@ class ArticleSweeper &lt; ActiveRecord::Observer
15 15 Article.find(article.parent_id_was).touch if article.parent_id_was
16 16 end
17 17 end
18   -
19   -
  18 +
  19 +
20 20 protected
21 21  
22 22 def expire_caches(article)
23 23 expire_blocks_cache(article.profile, [:article])
24 24  
25 25 return if !article.environment
26   -
  26 +
27 27 article.hierarchy(true).each { |a| a.touch if a != article }
28 28 env = article.profile.environment
29 29 if env && (env.portal_community == article.profile)
... ...
app/sweepers/category_sweeper.rb
... ... @@ -3,8 +3,10 @@ class CategorySweeper &lt; ActiveRecord::Observer
3 3 include SweeperHelper
4 4  
5 5 def after_save(category)
6   - # expire_fragment(category.environment.id.to_s + "_categories_menu")
7 6 expire_blocks_cache(category.environment, [:category])
  7 +
  8 + # Needed for environments with application layout
  9 + expire_fragment(category.environment.id.to_s + "_categories_menu")
8 10 end
9 11  
10 12 def after_destroy(category)
... ...
plugins/display_content/lib/display_content_block.rb
... ... @@ -86,5 +86,5 @@ class DisplayContentBlock &lt; Block
86 86 def self.expire_on
87 87 { :profile => [:article], :environment => [:article] }
88 88 end
89   -
  89 +
90 90 end
... ...
test/unit/block_test.rb
... ... @@ -160,7 +160,7 @@ class BlockTest &lt; ActiveSupport::TestCase
160 160 conditions = Block.expire_on
161 161 assert conditions[:profile].kind_of?(Array)
162 162 end
163   -
  163 +
164 164 should 'inform conditions for expiration on environment context' do
165 165 conditions = Block.expire_on
166 166 assert conditions[:environment].kind_of?(Array)
... ...