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