Commit dff012cae6683cf1a5fd6abf1ddea525852dc195
1 parent
a25c405e
Exists in
master
and in
28 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
@@ -109,7 +109,12 @@ class FriendsController < MyProfileController | @@ -109,7 +109,12 @@ class FriendsController < MyProfileController | ||
109 | 109 | ||
110 | protected | 110 | protected |
111 | 111 | ||
112 | + class << self | ||
112 | def per_page | 113 | def per_page |
113 | 10 | 114 | 10 |
114 | end | 115 | end |
116 | + end | ||
117 | + def per_page | ||
118 | + self.class.per_page | ||
119 | + end | ||
115 | end | 120 | end |
app/controllers/public/profile_controller.rb
@@ -105,6 +105,11 @@ class ProfileController < PublicController | @@ -105,6 +105,11 @@ class ProfileController < PublicController | ||
105 | end | 105 | end |
106 | 106 | ||
107 | def per_page | 107 | def per_page |
108 | - 10 | 108 | + self.class.per_page |
109 | + end | ||
110 | + class << self | ||
111 | + def per_page | ||
112 | + 10 | ||
113 | + end | ||
109 | end | 114 | end |
110 | end | 115 | end |
app/models/person.rb
@@ -250,7 +250,14 @@ class Person < Profile | @@ -250,7 +250,14 @@ class Person < Profile | ||
250 | end | 250 | end |
251 | 251 | ||
252 | def cache_keys(params = {}) | 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 | end | 261 | end |
255 | 262 | ||
256 | def communities_cache_key(params = {}) | 263 | def communities_cache_key(params = {}) |
app/sweepers/article_sweeper.rb
@@ -13,7 +13,7 @@ class ArticleSweeper < ActiveRecord::Observer | @@ -13,7 +13,7 @@ class ArticleSweeper < ActiveRecord::Observer | ||
13 | protected | 13 | protected |
14 | 14 | ||
15 | def expire_caches(article) | 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 | blocks = (article.profile.blocks + article.profile.environment.blocks).select{|b|[RecentDocumentsBlock, BlogArchivesBlock].any?{|c| b.kind_of?(c)}} | 17 | blocks = (article.profile.blocks + article.profile.environment.blocks).select{|b|[RecentDocumentsBlock, BlogArchivesBlock].any?{|c| b.kind_of?(c)}} |
18 | blocks.map(&:cache_keys).each{|ck|expire_timeout_fragment(ck)} | 18 | blocks.map(&:cache_keys).each{|ck|expire_timeout_fragment(ck)} |
19 | env = article.profile.environment | 19 | env = article.profile.environment |
app/sweepers/friendship_sweeper.rb
@@ -18,10 +18,16 @@ protected | @@ -18,10 +18,16 @@ protected | ||
18 | end | 18 | end |
19 | 19 | ||
20 | def expire_cache(profile) | 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 | blocks = profile.blocks.select{|b| b.kind_of?(FriendsBlock)} | 32 | blocks = profile.blocks.select{|b| b.kind_of?(FriendsBlock)} |
27 | blocks.map(&:cache_keys).each{|ck|expire_timeout_fragment(ck)} | 33 | blocks.map(&:cache_keys).each{|ck|expire_timeout_fragment(ck)} |
app/sweepers/role_assignment_sweeper.rb
@@ -18,9 +18,8 @@ protected | @@ -18,9 +18,8 @@ protected | ||
18 | end | 18 | end |
19 | 19 | ||
20 | def expire_cache(profile) | 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 | profile.blocks_to_expire_cache.each { |block| | 25 | profile.blocks_to_expire_cache.each { |block| |
test/unit/blog_test.rb
@@ -134,8 +134,8 @@ class BlogTest < ActiveSupport::TestCase | @@ -134,8 +134,8 @@ class BlogTest < ActiveSupport::TestCase | ||
134 | p = create_user('testuser').person | 134 | p = create_user('testuser').person |
135 | blog = Blog.create!(:name => 'Blog test', :profile => p) | 135 | blog = Blog.create!(:name => 'Blog test', :profile => p) |
136 | post = Article.create!(:name => 'First post', :profile => p, :parent => blog) | 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 | post.name = 'Edited First post' | 139 | post.name = 'Edited First post' |
140 | assert post.save! | 140 | assert post.save! |
141 | end | 141 | end |