Try to take photos query out of views
This commit is contained in:
parent
fcb0e07dd7
commit
fce428826c
7 changed files with 29 additions and 6 deletions
|
|
@ -136,11 +136,14 @@ class AspectsController < ApplicationController
|
|||
|
||||
private
|
||||
def hashes_for_posts posts
|
||||
comment_hash = Comment.hash_from_post_ids posts.map{|p| p.id}
|
||||
post_ids = posts.map{|p| p.id}
|
||||
comment_hash = Comment.hash_from_post_ids post_ids
|
||||
person_hash = Person.from_post_comment_hash comment_hash
|
||||
photo_hash = Photo.hash_from_post_ids post_ids
|
||||
|
||||
posts.map do |post|
|
||||
{:post => post,
|
||||
:photos => photo_hash[post.id],
|
||||
:person => post.person,
|
||||
:comments => comment_hash[post.id].map do |comment|
|
||||
{:comment => comment,
|
||||
|
|
|
|||
|
|
@ -102,12 +102,15 @@ class PeopleController < ApplicationController
|
|||
|
||||
private
|
||||
def hashes_for_posts posts
|
||||
comment_hash = Comment.hash_from_post_ids posts.map{|p| p.id}
|
||||
post_ids = posts.map{|p| p.id}
|
||||
comment_hash = Comment.hash_from_post_ids post_ids
|
||||
person_hash = Person.from_post_comment_hash comment_hash
|
||||
photo_hash = Photo.hash_from_post_ids post_ids
|
||||
|
||||
posts.map do |post|
|
||||
{:post => post,
|
||||
:person => @person,
|
||||
:photos => photo_hash[post.id],
|
||||
:comments => comment_hash[post.id].map do |comment|
|
||||
{:comment => comment,
|
||||
:person => person_hash[comment.person_id],
|
||||
|
|
|
|||
|
|
@ -39,6 +39,7 @@ class StatusMessagesController < ApplicationController
|
|||
:locals => {
|
||||
:post => @status_message,
|
||||
:person => @status_message.person,
|
||||
:photos => @status_message.photos,
|
||||
:comments => [],
|
||||
:aspects => current_user.aspects,
|
||||
:current_user => current_user
|
||||
|
|
|
|||
|
|
@ -12,9 +12,10 @@ module SocketsHelper
|
|||
def action_hash(uid, object, opts={})
|
||||
begin
|
||||
user = User.find_by_id uid
|
||||
if object.is_a? Post
|
||||
if object.is_a? StatusMessage
|
||||
post_hash = {:post => object,
|
||||
:person => object.person,
|
||||
:photos => object.photos,
|
||||
:comments => object.comments.map{|c|
|
||||
{:comment => c,
|
||||
:person => c.person
|
||||
|
|
|
|||
|
|
@ -102,5 +102,20 @@ class Photo < Post
|
|||
}
|
||||
end
|
||||
|
||||
def self.hash_from_post_ids post_ids
|
||||
hash = {}
|
||||
photos = self.on_statuses(post_ids)
|
||||
post_ids.each do |id|
|
||||
hash[id] = []
|
||||
end
|
||||
photos.each do |photo|
|
||||
hash[photo.status_message_id] << photo
|
||||
end
|
||||
hash.each_value {|photos| photos.sort!{|p1, p2| p1.created_at <=> p2.created_at }}
|
||||
hash
|
||||
end
|
||||
scope :on_statuses, lambda { |post_ids|
|
||||
where(:status_message_id.in => post_ids)
|
||||
}
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@
|
|||
= render 'shared/reshare', :current_user => current_user, :post => post if post.is_a? StatusMessage
|
||||
= link_to t('delete'), status_message_path(post), :confirm => t('are_you_sure'), :method => :delete, :remote => true, :class => "delete"
|
||||
|
||||
= render 'status_messages/status_message', :post => post
|
||||
= render 'status_messages/status_message', :post => post, :photos => post.photos
|
||||
|
||||
.info
|
||||
%span.time= link_to(how_long_ago(post), status_message_path(post))
|
||||
|
|
|
|||
|
|
@ -5,8 +5,8 @@
|
|||
%p
|
||||
= markdownify(post.message, :youtube_maps => post[:youtube_titles])
|
||||
|
||||
- if post.photos.count > 0
|
||||
- if photos.count > 0
|
||||
.photo_attachments
|
||||
- for photo in post.photos
|
||||
- for photo in photos
|
||||
= link_to (image_tag photo.url(:thumb_medium)), photo_path(photo)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue