diff --git a/app/models/blog.rb b/app/models/blog.rb index 38ab37a..7a8eabd 100644 --- a/app/models/blog.rb +++ b/app/models/blog.rb @@ -72,4 +72,8 @@ class Blog < Folder alias :display_posts_in_current_language? :display_posts_in_current_language + def empty? + posts.compact.empty? + end + end diff --git a/app/sweepers/profile_sweeper.rb b/app/sweepers/profile_sweeper.rb index c83f02c..926d36a 100644 --- a/app/sweepers/profile_sweeper.rb +++ b/app/sweepers/profile_sweeper.rb @@ -25,10 +25,23 @@ protected profile.blocks.each do |block| expire_timeout_fragment(block.cache_key) end + + expire_blogs(profile) if profile.organization? end def expire_statistics_block_cache(profile) blocks = profile.environment.blocks.select { |b| b.kind_of?(EnvironmentStatisticsBlock) } blocks.map(&:cache_key).each{|ck|expire_timeout_fragment(ck)} end + + def expire_blogs(profile) + profile.blogs.select{|b| !b.empty?}.each do |blog| + pages = blog.posts.count / blog.posts_per_page + 1 + ([nil] + (1..pages).to_a).each do |i| + expire_timeout_fragment(blog.cache_key({:npage => i})) + expire_timeout_fragment(blog.cache_key({:npage => i}, profile)) + end + end + end + end diff --git a/app/views/content_viewer/blog_page.rhtml b/app/views/content_viewer/blog_page.rhtml index a18022c..4eba287 100644 --- a/app/views/content_viewer/blog_page.rhtml +++ b/app/views/content_viewer/blog_page.rhtml @@ -9,5 +9,5 @@
- <%= (@posts.compact.empty? ? content_tag('em', _('(no posts)')) : list_posts(@posts, @page.visualization_format)) %> + <%= (@page.empty? ? content_tag('em', _('(no posts)')) : list_posts(@posts, @page.visualization_format)) %>
diff --git a/test/unit/blog_test.rb b/test/unit/blog_test.rb index fab6738..1e17513 100644 --- a/test/unit/blog_test.rb +++ b/test/unit/blog_test.rb @@ -211,4 +211,11 @@ class BlogTest < ActiveSupport::TestCase assert !folder.accept_uploads? end + should 'know when blog has or when has no posts' do + blog = fast_create(Blog) + assert blog.empty? + fast_create(TextileArticle, :parent_id => blog.id) + assert ! blog.empty? + end + end -- libgit2 0.21.2