From 690951dcd175da3e8b1a39c2452451f5f8b13118 Mon Sep 17 00:00:00 2001 From: Raphael Date: Thu, 25 Nov 2010 22:52:24 -0500 Subject: [PATCH] Take a query out of the views --- app/helpers/sockets_helper.rb | 2 +- app/views/shared/_stream.haml | 4 ++-- app/views/shared/_stream_element.html.haml | 2 +- spec/controllers/aspects_controller_spec.rb | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/helpers/sockets_helper.rb b/app/helpers/sockets_helper.rb index 684197529..e83bb7c27 100644 --- a/app/helpers/sockets_helper.rb +++ b/app/helpers/sockets_helper.rb @@ -13,7 +13,7 @@ module SocketsHelper begin user = User.find_by_id uid if object.is_a? Post - v = render_to_string(:partial => 'shared/stream_element', :locals => {:post => object, :current_user => user}) + v = render_to_string(:partial => 'shared/stream_element', :locals => {:post => object, :current_user => user, :aspects => user.aspects}) elsif object.is_a? Person v = render_to_string(:partial => type_partial(object), :locals => {:single_aspect_form => opts[:single_aspect_form], :person => object, :aspects => user.aspects, :current_user => user}) elsif object.is_a? Comment diff --git a/app/views/shared/_stream.haml b/app/views/shared/_stream.haml index a58c4d6f1..5a2b15154 100644 --- a/app/views/shared/_stream.haml +++ b/app/views/shared/_stream.haml @@ -3,5 +3,5 @@ -# the COPYRIGHT file. %ul{:class => 'stream', :id => 'main_stream'} - - for post in posts - = render 'shared/stream_element', :post => post + - for post in @posts + = render 'shared/stream_element', :post => post, :aspects => @aspects diff --git a/app/views/shared/_stream_element.html.haml b/app/views/shared/_stream_element.html.haml index ba5c42f89..6fcd30826 100644 --- a/app/views/shared/_stream_element.html.haml +++ b/app/views/shared/_stream_element.html.haml @@ -17,7 +17,7 @@ - if post.public? %li= t('the_world') - else - - for aspect in current_user.aspects_with_post( post.id ) + - for aspect in aspects.select{|a| a.post_ids.include?(post.id)} %li= link_to aspect.name, aspect .right diff --git a/spec/controllers/aspects_controller_spec.rb b/spec/controllers/aspects_controller_spec.rb index 0f162dec5..c017d5554 100644 --- a/spec/controllers/aspects_controller_spec.rb +++ b/spec/controllers/aspects_controller_spec.rb @@ -49,7 +49,7 @@ describe AspectsController do it 'takes time' do Benchmark.realtime{ get :index - }.should < 0 + }.should < 3 end end end