From 479ca8671327867cedaf1a81e2224835d810871b Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Wed, 14 Aug 2013 12:18:54 -0400 Subject: [PATCH] FIX: Don't select columns if we don't have to. --- app/controllers/post_actions_controller.rb | 20 ++----------------- .../post_action_user_serializer.rb | 20 +++++++++++++++---- 2 files changed, 18 insertions(+), 22 deletions(-) diff --git a/app/controllers/post_actions_controller.rb b/app/controllers/post_actions_controller.rb index 860d5f359..b62f2a1b4 100644 --- a/app/controllers/post_actions_controller.rb +++ b/app/controllers/post_actions_controller.rb @@ -28,25 +28,9 @@ class PostActionsController < ApplicationController def users guardian.ensure_can_see_post_actors!(@post.topic, @post_action_type_id) - users = User.select(['null as post_url', - 'users.id', - 'users.username', - 'users.username_lower', - 'users.email', - 'users.use_uploaded_avatar', - 'users.uploaded_avatar_id', - 'users.uploaded_avatar_template', - 'post_actions.related_post_id']) - .joins(:post_actions) - .where(['post_actions.post_id = ? and post_actions.post_action_type_id = ? and post_actions.deleted_at IS NULL', @post.id, @post_action_type_id]) - .to_a + post_actions = @post.post_actions.where(post_action_type_id: @post_action_type_id).includes(:user) - urls = Post.urls(users.map{|u| u.related_post_id}) - users.each do |u| - u.post_url = urls[u.related_post_id.to_i] - end - - render_serialized(users, PostActionUserSerializer) + render_serialized(post_actions.to_a, PostActionUserSerializer) end def destroy diff --git a/app/serializers/post_action_user_serializer.rb b/app/serializers/post_action_user_serializer.rb index 19a4f6895..582e9263b 100644 --- a/app/serializers/post_action_user_serializer.rb +++ b/app/serializers/post_action_user_serializer.rb @@ -1,8 +1,20 @@ class PostActionUserSerializer < BasicUserSerializer - attributes :post_url + attributes :id, :username, :avatar_template, :post_url - # reserved - def post_url - object.post_url + def id + object.user.id end + + def username + object.user.username + end + + def avatar_template + object.user.avatar_template + end + + def post_url + object.related_post_id + end + end