Commit c97d1f564dde3e91e6181c6b48c8741aaf9b718c
Committed by
Daniela Feitosa
1 parent
14532049
Exists in
master
and in
28 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
app/sweepers/profile_sweeper.rb
... | ... | @@ -25,10 +25,23 @@ protected |
25 | 25 | profile.blocks.each do |block| |
26 | 26 | expire_timeout_fragment(block.cache_key) |
27 | 27 | end |
28 | + | |
29 | + expire_blogs(profile) if profile.organization? | |
28 | 30 | end |
29 | 31 | |
30 | 32 | def expire_statistics_block_cache(profile) |
31 | 33 | blocks = profile.environment.blocks.select { |b| b.kind_of?(EnvironmentStatisticsBlock) } |
32 | 34 | blocks.map(&:cache_key).each{|ck|expire_timeout_fragment(ck)} |
33 | 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 | 47 | end | ... | ... |
app/views/content_viewer/blog_page.rhtml
... | ... | @@ -9,5 +9,5 @@ |
9 | 9 | </div> |
10 | 10 | <hr class="pre-posts"/> |
11 | 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 | 13 | </div> | ... | ... |
test/unit/blog_test.rb
... | ... | @@ -211,4 +211,11 @@ class BlogTest < ActiveSupport::TestCase |
211 | 211 | assert !folder.accept_uploads? |
212 | 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 | 221 | end | ... | ... |