Commit c97d1f564dde3e91e6181c6b48c8741aaf9b718c
Committed by
Daniela Feitosa
1 parent
14532049
Exists in
master
and in
23 other branches
Expires blog cache after organization changes its URL address
(ActionItem1941)
Showing
4 changed files
with
25 additions
and
1 deletions
Show diff stats
app/models/blog.rb
| @@ -72,4 +72,8 @@ class Blog < Folder | @@ -72,4 +72,8 @@ class Blog < Folder | ||
| 72 | 72 | ||
| 73 | alias :display_posts_in_current_language? :display_posts_in_current_language | 73 | alias :display_posts_in_current_language? :display_posts_in_current_language |
| 74 | 74 | ||
| 75 | + def empty? | ||
| 76 | + posts.compact.empty? | ||
| 77 | + end | ||
| 78 | + | ||
| 75 | end | 79 | end |
app/sweepers/profile_sweeper.rb
| @@ -25,10 +25,23 @@ protected | @@ -25,10 +25,23 @@ protected | ||
| 25 | profile.blocks.each do |block| | 25 | profile.blocks.each do |block| |
| 26 | expire_timeout_fragment(block.cache_key) | 26 | expire_timeout_fragment(block.cache_key) |
| 27 | end | 27 | end |
| 28 | + | ||
| 29 | + expire_blogs(profile) if profile.organization? | ||
| 28 | end | 30 | end |
| 29 | 31 | ||
| 30 | def expire_statistics_block_cache(profile) | 32 | def expire_statistics_block_cache(profile) |
| 31 | blocks = profile.environment.blocks.select { |b| b.kind_of?(EnvironmentStatisticsBlock) } | 33 | blocks = profile.environment.blocks.select { |b| b.kind_of?(EnvironmentStatisticsBlock) } |
| 32 | blocks.map(&:cache_key).each{|ck|expire_timeout_fragment(ck)} | 34 | blocks.map(&:cache_key).each{|ck|expire_timeout_fragment(ck)} |
| 33 | end | 35 | end |
| 36 | + | ||
| 37 | + def expire_blogs(profile) | ||
| 38 | + profile.blogs.select{|b| !b.empty?}.each do |blog| | ||
| 39 | + pages = blog.posts.count / blog.posts_per_page + 1 | ||
| 40 | + ([nil] + (1..pages).to_a).each do |i| | ||
| 41 | + expire_timeout_fragment(blog.cache_key({:npage => i})) | ||
| 42 | + expire_timeout_fragment(blog.cache_key({:npage => i}, profile)) | ||
| 43 | + end | ||
| 44 | + end | ||
| 45 | + end | ||
| 46 | + | ||
| 34 | end | 47 | end |
app/views/content_viewer/blog_page.rhtml
| @@ -9,5 +9,5 @@ | @@ -9,5 +9,5 @@ | ||
| 9 | </div> | 9 | </div> |
| 10 | <hr class="pre-posts"/> | 10 | <hr class="pre-posts"/> |
| 11 | <div class="blog-posts"> | 11 | <div class="blog-posts"> |
| 12 | - <%= (@posts.compact.empty? ? content_tag('em', _('(no posts)')) : list_posts(@posts, @page.visualization_format)) %> | 12 | + <%= (@page.empty? ? content_tag('em', _('(no posts)')) : list_posts(@posts, @page.visualization_format)) %> |
| 13 | </div> | 13 | </div> |
test/unit/blog_test.rb
| @@ -211,4 +211,11 @@ class BlogTest < ActiveSupport::TestCase | @@ -211,4 +211,11 @@ class BlogTest < ActiveSupport::TestCase | ||
| 211 | assert !folder.accept_uploads? | 211 | assert !folder.accept_uploads? |
| 212 | end | 212 | end |
| 213 | 213 | ||
| 214 | + should 'know when blog has or when has no posts' do | ||
| 215 | + blog = fast_create(Blog) | ||
| 216 | + assert blog.empty? | ||
| 217 | + fast_create(TextileArticle, :parent_id => blog.id) | ||
| 218 | + assert ! blog.empty? | ||
| 219 | + end | ||
| 220 | + | ||
| 214 | end | 221 | end |