diff --git a/lib/diaspora/redis_cache.rb b/lib/diaspora/redis_cache.rb index ce4187965..4a10594df 100644 --- a/lib/diaspora/redis_cache.rb +++ b/lib/diaspora/redis_cache.rb @@ -45,7 +45,7 @@ class RedisCache def populate! # user executes query and gets back hashes - sql = @user.visible_posts_sql(:type => AspectStream::TYPES_OF_POST_IN_STREAM, :limit => CACHE_LIMIT, :order => self.order) + sql = @user.visible_posts_sql(:type => RedisCache.acceptable_types, :limit => CACHE_LIMIT, :order => self.order) hashes = Post.connection.select_all(sql) # hashes are inserted into set in a single transaction @@ -76,6 +76,12 @@ class RedisCache self.trim! end + # exposing the need to tie cache to a stream + # @return [Array] Acceptable Post types for the given cache + def self.acceptable_types + AspectStream::TYPES_OF_POST_IN_STREAM + end + protected # @return [Redis] def redis diff --git a/lib/postzord/receiver.rb b/lib/postzord/receiver.rb index 3939f9715..801a66baa 100644 --- a/lib/postzord/receiver.rb +++ b/lib/postzord/receiver.rb @@ -15,7 +15,8 @@ class Postzord::Receiver # @return [Boolean] def cache? self.respond_to?(:update_cache!) && RedisCache.configured? && - @object.respond_to?(:triggers_caching?) && @object.triggers_caching? + @object.respond_to?(:triggers_caching?) && @object.triggers_caching? && + @object.respond_to?(:type) && RedisCache.acceptable_types.include?(@object.type) end end diff --git a/spec/lib/diaspora/redis_cache_spec.rb b/spec/lib/diaspora/redis_cache_spec.rb index 94ae8221d..98753fb55 100644 --- a/spec/lib/diaspora/redis_cache_spec.rb +++ b/spec/lib/diaspora/redis_cache_spec.rb @@ -173,5 +173,12 @@ describe RedisCache do end end + describe '.acceptable_types' do + #exposing the need to tie cache to a stream + it 'returns the types from the aspect stream' do + RedisCache.acceptable_types.should =~ AspectStream::TYPES_OF_POST_IN_STREAM + end + end + describe "#remove" end diff --git a/spec/lib/postzord/receiver_spec.rb b/spec/lib/postzord/receiver_spec.rb index f51164372..669b000fe 100644 --- a/spec/lib/postzord/receiver_spec.rb +++ b/spec/lib/postzord/receiver_spec.rb @@ -40,7 +40,9 @@ describe Postzord::Receiver do before do @receiver.stub(:respond_to?).with(:update_cache!).and_return(true) AppConfig[:redis_cache] = true - @receiver.instance_variable_set(:@object, mock(:triggers_caching? => true)) + + RedisCache.stub(:acceptable_types).and_return(["StatusMessage"]) + @receiver.instance_variable_set(:@object, mock(:triggers_caching? => true, :type => "StatusMessage")) end it 'returns true if the receiver responds to update_cache and the application has caching enabled' do @@ -66,6 +68,11 @@ describe Postzord::Receiver do @receiver.instance_variable_set(:@object, mock(:triggers_caching? => false)) @receiver.cache?.should be_false end + + it 'returns false if the object is not of acceptable type for the cache' do + @receiver.instance_variable_set(:@object, mock(:triggers_caching? => true, :type => "Photo")) + @receiver.cache?.should be_false + end end end