From 0da070c5ffb030709372947512134c450a11604c Mon Sep 17 00:00:00 2001 From: Karina Kwiatek Date: Fri, 31 Dec 2021 15:35:02 +0100 Subject: [PATCH] Move includes into `cursored_friends`/`cursored_followers` --- app/controllers/user_controller.rb | 8 ++++---- app/models/user/relationship_methods.rb | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/app/controllers/user_controller.rb b/app/controllers/user_controller.rb index a31bc566..edf88087 100644 --- a/app/controllers/user_controller.rb +++ b/app/controllers/user_controller.rb @@ -84,7 +84,7 @@ class UserController < ApplicationController def followers @title = 'Followers' - @user = User.where('LOWER(screen_name) = ?', params[:username].downcase).first! + @user = User.where('LOWER(screen_name) = ?', params[:username].downcase).includes(:profile).first! @users = @user.cursored_followers(last_id: params[:last_id]) @users_last_id = @users.map(&:id).min @more_data_available = !@user.cursored_followers(last_id: @users_last_id, size: 1).count.zero? @@ -98,8 +98,8 @@ class UserController < ApplicationController def friends @title = 'Following' - @user = User.where('LOWER(screen_name) = ?', params[:username].downcase).first! - @users = @user.cursored_friends(last_id: params[:last_id]).includes(:profile) + @user = User.where('LOWER(screen_name) = ?', params[:username].downcase).includes(:profile).first! + @users = @user.cursored_friends(last_id: params[:last_id]) @users_last_id = @users.map(&:id).min @more_data_available = !@user.cursored_friends(last_id: @users_last_id, size: 1).count.zero? @type = :friend @@ -112,7 +112,7 @@ class UserController < ApplicationController def questions @title = 'Questions' - @user = User.where('LOWER(screen_name) = ?', params[:username].downcase).first! + @user = User.where('LOWER(screen_name) = ?', params[:username].downcase).includes(:profile).first! @questions = @user.cursored_questions(author_is_anonymous: false, last_id: params[:last_id]) @questions_last_id = @questions.map(&:id).min @more_data_available = !@user.cursored_questions(author_is_anonymous: false, last_id: @questions_last_id, size: 1).count.zero? diff --git a/app/models/user/relationship_methods.rb b/app/models/user/relationship_methods.rb index 8093b6bc..b527fe25 100644 --- a/app/models/user/relationship_methods.rb +++ b/app/models/user/relationship_methods.rb @@ -7,10 +7,10 @@ module User::RelationshipMethods define_cursor_paginator :cursored_followers, :ordered_followers def ordered_friends - friends.reverse_order + friends.reverse_order.includes(:profile) end def ordered_followers - followers.reverse_order + followers.reverse_order.includes(:profile) end end