MS SM save sync cache if you have some sort of contacts

This commit is contained in:
Maxwell Salzberg 2011-11-07 19:52:48 -08:00
parent 0f19076b40
commit fe3fe0f5cc
2 changed files with 10 additions and 3 deletions

View file

@ -28,7 +28,11 @@ module Diaspora
if use_cache?(opts) if use_cache?(opts)
cache = RedisCache.new(self, opts[:order_field]) cache = RedisCache.new(self, opts[:order_field])
#cache.ensure_populated!(opts) #total hax
if self.contacts.where(:sharing => true, :receiving => true).count > 0
cache.ensure_populated!(opts)
end
name = klass.to_s.downcase name = klass.to_s.downcase
shareable_ids = cache.send(name+"_ids", opts[:max_time], opts[:limit] +1) shareable_ids = cache.send(name+"_ids", opts[:max_time], opts[:limit] +1)
end end
@ -159,6 +163,7 @@ module Diaspora
protected protected
# @return [Boolean] # @return [Boolean]
def use_cache?(opts) def use_cache?(opts)
RedisCache.configured? && RedisCache.supported_order?(opts[:order_field]) && opts[:all_aspects?].present? RedisCache.configured? && RedisCache.supported_order?(opts[:order_field]) && opts[:all_aspects?].present?
end end

View file

@ -102,8 +102,10 @@ describe User do
AppConfig[:redis_cache] = nil AppConfig[:redis_cache] = nil
end end
it "kicks off a job that will populate the latest 100 posts" do it "populates the cache if the user has a mutual contact" do
pending "we need a job for this - ensure_populated! is too costly to do synchronously for new users" RedisCache.any_instance.should_receive(:ensure_populated!)
alice.stub(:use_cache?).and_return(true)
alice.visible_shareable_ids(Post)
end end
it 'does not get used if if all_aspects? option is not present' do it 'does not get used if if all_aspects? option is not present' do