From 34f82d8bc160db114bd78cbf4a9f3c2ecc8b4514 Mon Sep 17 00:00:00 2001 From: Maxwell Salzberg Date: Mon, 3 Oct 2011 17:14:42 -0700 Subject: [PATCH] try an in query directly for the tags --- app/controllers/tag_followings_controller.rb | 1 - lib/stream/tag_stream.rb | 7 +++++-- spec/lib/stream/tag_stream_spec.rb | 8 ++++++++ 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/app/controllers/tag_followings_controller.rb b/app/controllers/tag_followings_controller.rb index 308478523..1ec4d11ed 100644 --- a/app/controllers/tag_followings_controller.rb +++ b/app/controllers/tag_followings_controller.rb @@ -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 diff --git a/lib/stream/tag_stream.rb b/lib/stream/tag_stream.rb index bf1855157..772a933a0 100644 --- a/lib/stream/tag_stream.rb +++ b/lib/stream/tag_stream.rb @@ -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 diff --git a/spec/lib/stream/tag_stream_spec.rb b/spec/lib/stream/tag_stream_spec.rb index 93050c839..ba6b80e77 100644 --- a/spec/lib/stream/tag_stream_spec.rb +++ b/spec/lib/stream/tag_stream_spec.rb @@ -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