From fe3fe0f5cc072a13581a525c5b4a5d8c6bdf503e Mon Sep 17 00:00:00 2001 From: Maxwell Salzberg Date: Mon, 7 Nov 2011 19:52:48 -0800 Subject: [PATCH] MS SM save sync cache if you have some sort of contacts --- lib/diaspora/user/querying.rb | 7 ++++++- spec/models/user/querying_spec.rb | 6 ++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/diaspora/user/querying.rb b/lib/diaspora/user/querying.rb index a93370f9d..fea5c6e4b 100644 --- a/lib/diaspora/user/querying.rb +++ b/lib/diaspora/user/querying.rb @@ -28,7 +28,11 @@ module Diaspora if use_cache?(opts) 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 shareable_ids = cache.send(name+"_ids", opts[:max_time], opts[:limit] +1) end @@ -159,6 +163,7 @@ module Diaspora protected # @return [Boolean] + def use_cache?(opts) RedisCache.configured? && RedisCache.supported_order?(opts[:order_field]) && opts[:all_aspects?].present? end diff --git a/spec/models/user/querying_spec.rb b/spec/models/user/querying_spec.rb index 2101d662e..d70b9500a 100644 --- a/spec/models/user/querying_spec.rb +++ b/spec/models/user/querying_spec.rb @@ -102,8 +102,10 @@ describe User do AppConfig[:redis_cache] = nil end - it "kicks off a job that will populate the latest 100 posts" do - pending "we need a job for this - ensure_populated! is too costly to do synchronously for new users" + it "populates the cache if the user has a mutual contact" do + RedisCache.any_instance.should_receive(:ensure_populated!) + alice.stub(:use_cache?).and_return(true) + alice.visible_shareable_ids(Post) end it 'does not get used if if all_aspects? option is not present' do