Commit dff012cae6683cf1a5fd6abf1ddea525852dc195
1 parent
a25c405e
Exists in
master
and in
29 other branches
ActionItem1055: adapting cache expiration code
Showing
7 changed files
with
34 additions
and
12 deletions
Show diff stats
app/controllers/my_profile/friends_controller.rb
app/controllers/public/profile_controller.rb
app/models/person.rb
| ... | ... | @@ -250,7 +250,14 @@ class Person < Profile |
| 250 | 250 | end |
| 251 | 251 | |
| 252 | 252 | def cache_keys(params = {}) |
| 253 | - [communities_cache_key] | |
| 253 | + result = [] | |
| 254 | + if params[:per_page] | |
| 255 | + pages = (self.communities.count.to_f / params[:per_page].to_f).ceil | |
| 256 | + (1..pages).each do |i| | |
| 257 | + result << self.communities_cache_key(:npage => i.to_s) | |
| 258 | + end | |
| 259 | + end | |
| 260 | + result | |
| 254 | 261 | end |
| 255 | 262 | |
| 256 | 263 | def communities_cache_key(params = {}) | ... | ... |
app/sweepers/article_sweeper.rb
| ... | ... | @@ -13,7 +13,7 @@ class ArticleSweeper < ActiveRecord::Observer |
| 13 | 13 | protected |
| 14 | 14 | |
| 15 | 15 | def expire_caches(article) |
| 16 | - article.hierarchy.each {|a| expire_fragment(/#{a.cache_key}/) } | |
| 16 | + article.hierarchy.each {|a| expire_fragment(a.cache_key) } | |
| 17 | 17 | blocks = (article.profile.blocks + article.profile.environment.blocks).select{|b|[RecentDocumentsBlock, BlogArchivesBlock].any?{|c| b.kind_of?(c)}} |
| 18 | 18 | blocks.map(&:cache_keys).each{|ck|expire_timeout_fragment(ck)} |
| 19 | 19 | env = article.profile.environment | ... | ... |
app/sweepers/friendship_sweeper.rb
| ... | ... | @@ -18,10 +18,16 @@ protected |
| 18 | 18 | end |
| 19 | 19 | |
| 20 | 20 | def expire_cache(profile) |
| 21 | - [profile.friends_cache_key, profile.manage_friends_cache_key].each { |ck| | |
| 22 | - cache_key = ck.gsub(/(.)-\d.*$/, '\1') | |
| 23 | - expire_timeout_fragment(/#{cache_key}/) | |
| 24 | - } | |
| 21 | + # public friends page | |
| 22 | + pages = profile.friends.count / ProfileController.per_page + 1 | |
| 23 | + (1..pages).each do |i| | |
| 24 | + expire_timeout_fragment(profile.friends_cache_key(:npage => i.to_s)) | |
| 25 | + end | |
| 26 | + # manage friends page | |
| 27 | + pages = profile.friends.count / FriendsController.per_page + 1 | |
| 28 | + (1..pages).each do |i| | |
| 29 | + expire_timeout_fragment(profile.manage_friends_cache_key(:npage => i.to_s)) | |
| 30 | + end | |
| 25 | 31 | |
| 26 | 32 | blocks = profile.blocks.select{|b| b.kind_of?(FriendsBlock)} |
| 27 | 33 | blocks.map(&:cache_keys).each{|ck|expire_timeout_fragment(ck)} | ... | ... |
app/sweepers/role_assignment_sweeper.rb
| ... | ... | @@ -18,9 +18,8 @@ protected |
| 18 | 18 | end |
| 19 | 19 | |
| 20 | 20 | def expire_cache(profile) |
| 21 | - profile.cache_keys.each { |ck| | |
| 22 | - cache_key = ck.gsub(/(.)-\d.*$/, '\1') | |
| 23 | - expire_timeout_fragment(/#{cache_key}/) | |
| 21 | + profile.cache_keys(:per_page => ProfileController.per_page).each { |ck| | |
| 22 | + expire_timeout_fragment(ck) | |
| 24 | 23 | } |
| 25 | 24 | |
| 26 | 25 | profile.blocks_to_expire_cache.each { |block| | ... | ... |
test/unit/blog_test.rb
| ... | ... | @@ -134,8 +134,8 @@ class BlogTest < ActiveSupport::TestCase |
| 134 | 134 | p = create_user('testuser').person |
| 135 | 135 | blog = Blog.create!(:name => 'Blog test', :profile => p) |
| 136 | 136 | post = Article.create!(:name => 'First post', :profile => p, :parent => blog) |
| 137 | - ArticleSweeper.any_instance.expects(:expire_fragment).with(/#{blog.cache_key}/) | |
| 138 | - ArticleSweeper.any_instance.expects(:expire_fragment).with(/#{post.cache_key}/) | |
| 137 | + ArticleSweeper.any_instance.expects(:expire_fragment).with(blog.cache_key) | |
| 138 | + ArticleSweeper.any_instance.expects(:expire_fragment).with(post.cache_key) | |
| 139 | 139 | post.name = 'Edited First post' |
| 140 | 140 | assert post.save! |
| 141 | 141 | end | ... | ... |