try an in query directly for the tags

This commit is contained in:
Maxwell Salzberg 2011-10-03 17:14:42 -07:00
parent 0aa49a8d73
commit 34f82d8bc1
3 changed files with 13 additions and 3 deletions

View file

@ -10,7 +10,6 @@ class TagFollowingsController < ApplicationController
def index
@stream = TagStream.new(current_user, :max_time => params[:max_time], :order => sort_order)
if params[:only_posts]
render :partial => 'shared/stream', :locals => {:posts => @stream.posts}
else

View file

@ -18,8 +18,7 @@ class TagStream < BaseStream
[]
else
@posts ||= StatusMessage.owned_or_visible_by_user(user).
tagged_with([tag_string], :any => true).
where(:public => true).
joins(:tags).where(:tags => {:name => tag_array}).
for_a_stream(@max_time, @order)
end
end
@ -39,6 +38,10 @@ class TagStream < BaseStream
@tag_string ||= tags.join(', '){|tag| tag.name}.to_s
end
def tag_array
tags.map{|x| x.name}
end
def tags
@tags = user.followed_tags
end

View file

@ -4,9 +4,17 @@ require File.join(Rails.root, 'spec', 'shared_behaviors', 'stream')
describe TagStream do
before do
@stream = TagStream.new(Factory(:user), :max_time => Time.now, :order => 'updated_at')
@stream.stub(:tag_string).and_return("foo")
end
describe 'shared behaviors' do
it_should_behave_like 'it is a stream'
end
describe 'posts' do
it 'explains the query' do
puts @stream.posts.to_sql
end
end
end