diff --git a/app/controllers/my_profile/friends_controller.rb b/app/controllers/my_profile/friends_controller.rb index 0a70611..15081f3 100644 --- a/app/controllers/my_profile/friends_controller.rb +++ b/app/controllers/my_profile/friends_controller.rb @@ -109,7 +109,12 @@ class FriendsController < MyProfileController protected + class << self def per_page 10 end + end + def per_page + self.class.per_page + end end diff --git a/app/controllers/public/profile_controller.rb b/app/controllers/public/profile_controller.rb index ef80e92..2ba8f7f 100644 --- a/app/controllers/public/profile_controller.rb +++ b/app/controllers/public/profile_controller.rb @@ -105,6 +105,11 @@ class ProfileController < PublicController end def per_page - 10 + self.class.per_page + end + class << self + def per_page + 10 + end end end diff --git a/app/models/person.rb b/app/models/person.rb index 76ee178..574b83c 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -250,7 +250,14 @@ class Person < Profile end def cache_keys(params = {}) - [communities_cache_key] + result = [] + if params[:per_page] + pages = (self.communities.count.to_f / params[:per_page].to_f).ceil + (1..pages).each do |i| + result << self.communities_cache_key(:npage => i.to_s) + end + end + result end def communities_cache_key(params = {}) diff --git a/app/sweepers/article_sweeper.rb b/app/sweepers/article_sweeper.rb index cc35ad7..d0a0650 100644 --- a/app/sweepers/article_sweeper.rb +++ b/app/sweepers/article_sweeper.rb @@ -13,7 +13,7 @@ class ArticleSweeper < ActiveRecord::Observer protected def expire_caches(article) - article.hierarchy.each {|a| expire_fragment(/#{a.cache_key}/) } + article.hierarchy.each {|a| expire_fragment(a.cache_key) } blocks = (article.profile.blocks + article.profile.environment.blocks).select{|b|[RecentDocumentsBlock, BlogArchivesBlock].any?{|c| b.kind_of?(c)}} blocks.map(&:cache_keys).each{|ck|expire_timeout_fragment(ck)} env = article.profile.environment diff --git a/app/sweepers/friendship_sweeper.rb b/app/sweepers/friendship_sweeper.rb index 5a50be8..175cafe 100644 --- a/app/sweepers/friendship_sweeper.rb +++ b/app/sweepers/friendship_sweeper.rb @@ -18,10 +18,16 @@ protected end def expire_cache(profile) - [profile.friends_cache_key, profile.manage_friends_cache_key].each { |ck| - cache_key = ck.gsub(/(.)-\d.*$/, '\1') - expire_timeout_fragment(/#{cache_key}/) - } + # public friends page + pages = profile.friends.count / ProfileController.per_page + 1 + (1..pages).each do |i| + expire_timeout_fragment(profile.friends_cache_key(:npage => i.to_s)) + end + # manage friends page + pages = profile.friends.count / FriendsController.per_page + 1 + (1..pages).each do |i| + expire_timeout_fragment(profile.manage_friends_cache_key(:npage => i.to_s)) + end blocks = profile.blocks.select{|b| b.kind_of?(FriendsBlock)} blocks.map(&:cache_keys).each{|ck|expire_timeout_fragment(ck)} diff --git a/app/sweepers/role_assignment_sweeper.rb b/app/sweepers/role_assignment_sweeper.rb index 7e79068..a4cea59 100644 --- a/app/sweepers/role_assignment_sweeper.rb +++ b/app/sweepers/role_assignment_sweeper.rb @@ -18,9 +18,8 @@ protected end def expire_cache(profile) - profile.cache_keys.each { |ck| - cache_key = ck.gsub(/(.)-\d.*$/, '\1') - expire_timeout_fragment(/#{cache_key}/) + profile.cache_keys(:per_page => ProfileController.per_page).each { |ck| + expire_timeout_fragment(ck) } profile.blocks_to_expire_cache.each { |block| diff --git a/test/unit/blog_test.rb b/test/unit/blog_test.rb index 07ae372..f39f08c 100644 --- a/test/unit/blog_test.rb +++ b/test/unit/blog_test.rb @@ -134,8 +134,8 @@ class BlogTest < ActiveSupport::TestCase p = create_user('testuser').person blog = Blog.create!(:name => 'Blog test', :profile => p) post = Article.create!(:name => 'First post', :profile => p, :parent => blog) - ArticleSweeper.any_instance.expects(:expire_fragment).with(/#{blog.cache_key}/) - ArticleSweeper.any_instance.expects(:expire_fragment).with(/#{post.cache_key}/) + ArticleSweeper.any_instance.expects(:expire_fragment).with(blog.cache_key) + ArticleSweeper.any_instance.expects(:expire_fragment).with(post.cache_key) post.name = 'Edited First post' assert post.save! end -- libgit2 0.21.2