dg iz added some more documentation and only caching on all aspects
This commit is contained in:
parent
6ea540fb94
commit
97342630c4
4 changed files with 38 additions and 5 deletions
|
|
@ -24,7 +24,7 @@ module Diaspora
|
|||
def visible_post_ids(opts={})
|
||||
opts = prep_opts(opts)
|
||||
|
||||
if AppConfig[:redis_cache] && RedisCache.supported_order?(opts[:order_field])
|
||||
if AppConfig[:redis_cache] && RedisCache.supported_order?(opts[:order_field]) && opts[:all_aspects?].present?
|
||||
cache = RedisCache.new(self, opts[:order_field])
|
||||
|
||||
cache.ensure_populated!
|
||||
|
|
|
|||
|
|
@ -39,7 +39,8 @@ class AspectStream < BaseStream
|
|||
# @return [ActiveRecord::Association<Post>] AR association of posts
|
||||
def posts
|
||||
# NOTE(this should be something like Post.all_for_stream(@user, aspect_ids, {}) that calls visible_posts
|
||||
@posts ||= user.visible_posts(:by_members_of => aspect_ids,
|
||||
@posts ||= user.visible_posts(:all_aspects? => for_all_aspects?,
|
||||
:by_members_of => aspect_ids,
|
||||
:type => TYPES_OF_POST_IN_STREAM,
|
||||
:order => "#{order} DESC",
|
||||
:max_time => max_time
|
||||
|
|
@ -51,6 +52,7 @@ class AspectStream < BaseStream
|
|||
@people ||= Person.all_from_aspects(aspect_ids, user).includes(:profile)
|
||||
end
|
||||
|
||||
# @return [String] URL
|
||||
def link(opts={})
|
||||
Rails.application.routes.url_helpers.aspects_path(opts.merge(:a_ids => aspect_ids))
|
||||
end
|
||||
|
|
@ -64,16 +66,26 @@ class AspectStream < BaseStream
|
|||
end
|
||||
end
|
||||
|
||||
# Only ajax in the stream if all aspects are present.
|
||||
# In this case, we know we're on the first page of the stream,
|
||||
# as the default view for aspects/index is showing posts from
|
||||
# all a user's aspects.
|
||||
#
|
||||
# @return [Boolean] see #for_all_aspects?
|
||||
def ajax_stream?
|
||||
for_all_aspects?
|
||||
end
|
||||
|
||||
# The title that will display at the top of the stream's
|
||||
# publisher box.
|
||||
#
|
||||
# @return [String]
|
||||
def title
|
||||
if self.for_all_aspects?
|
||||
I18n.t('aspects.aspect_stream.stream')
|
||||
else
|
||||
else
|
||||
self.aspects.to_sentence
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Determine whether or not the stream is displaying across
|
||||
|
|
@ -84,6 +96,9 @@ class AspectStream < BaseStream
|
|||
@all_aspects ||= aspect_ids.length == user.aspects.size
|
||||
end
|
||||
|
||||
# Provides a translated title for contacts box on the right pane.
|
||||
#
|
||||
# @return [String]
|
||||
def contacts_title
|
||||
if self.for_all_aspects? || self.aspect_ids.size > 1
|
||||
I18n.t('_contacts')
|
||||
|
|
@ -92,6 +107,10 @@ class AspectStream < BaseStream
|
|||
end
|
||||
end
|
||||
|
||||
# Provides a link to the user to the contacts page that corresponds with
|
||||
# the stream's active aspects.
|
||||
#
|
||||
# @return [String] Link to contacts
|
||||
def contacts_link
|
||||
if for_all_aspects? || aspect_ids.size > 1
|
||||
Rails.application.routes.url_helpers.contacts_path
|
||||
|
|
|
|||
|
|
@ -73,6 +73,14 @@ describe AspectStream do
|
|||
@alice.should_receive(:visible_posts).with(hash_including(:max_time => instance_of(Time))).and_return(stub.as_null_object)
|
||||
stream.posts
|
||||
end
|
||||
|
||||
it 'passes for_all_aspects to visible posts' do
|
||||
stream = AspectStream.new(@alice, [1,2], :max_time => 123)
|
||||
all_aspects = mock
|
||||
stream.stub(:for_all_aspects?).and_return(all_aspects)
|
||||
@alice.should_receive(:visible_posts).with(hash_including(:all_aspects? => all_aspects)).and_return(stub.as_null_object)
|
||||
stream.posts
|
||||
end
|
||||
end
|
||||
|
||||
describe '#people' do
|
||||
|
|
|
|||
|
|
@ -88,7 +88,7 @@ describe User do
|
|||
context "RedisCache" do
|
||||
before do
|
||||
AppConfig[:redis_cache] = true
|
||||
@opts = {:order => "created_at DESC"}
|
||||
@opts = {:order => "created_at DESC", :all_aspects? => true}
|
||||
end
|
||||
|
||||
after do
|
||||
|
|
@ -103,6 +103,12 @@ describe User do
|
|||
alice.visible_post_ids(@opts)
|
||||
end
|
||||
|
||||
it 'does not get used if if all_aspects? option is not present' do
|
||||
RedisCache.should_not_receive(:new)
|
||||
|
||||
alice.visible_post_ids(@opts.merge({:all_aspects? => false}))
|
||||
end
|
||||
|
||||
describe "#ensure_populated_cache" do
|
||||
it 'does nothing if the cache is already populated'
|
||||
it 're-populates the cache with the latest posts (in hashes)'
|
||||
|
|
|
|||
Loading…
Reference in a new issue