From 8520dbc4b9b4373698a09ade91246df660156efb Mon Sep 17 00:00:00 2001 From: Karina Kwiatek Date: Tue, 31 Jan 2023 13:59:05 +0100 Subject: [PATCH] De-duplicate relationship pagination logic --- app/controllers/user_controller.rb | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/app/controllers/user_controller.rb b/app/controllers/user_controller.rb index e4c0f059..25c05efe 100644 --- a/app/controllers/user_controller.rb +++ b/app/controllers/user_controller.rb @@ -17,9 +17,7 @@ class UserController < ApplicationController end def followers - @relationships = @user.cursored_follower_relationships(last_id: params[:last_id]) - @relationships_last_id = @relationships.map(&:id).min - @more_data_available = !@user.cursored_follower_relationships(last_id: @relationships_last_id, size: 1).count.zero? + paginate_relationships(:cursored_follower_relationships) @users = @relationships.map(&:source) own_followings = find_own_relationships(current_user&.active_follow_relationships) own_blocks = find_own_relationships(current_user&.active_block_relationships) @@ -31,9 +29,7 @@ class UserController < ApplicationController end def followings - @relationships = @user.cursored_following_relationships(last_id: params[:last_id]) - @relationships_last_id = @relationships.map(&:id).min - @more_data_available = !@user.cursored_following_relationships(last_id: @relationships_last_id, size: 1).count.zero? + paginate_relationships(:cursored_following_relationships) @users = @relationships.map(&:target) own_followings = find_own_relationships(current_user&.active_follow_relationships) own_blocks = find_own_relationships(current_user&.active_block_relationships) @@ -79,6 +75,12 @@ class UserController < ApplicationController relationships.where(target_id: @users.map(&:id))&.select(:target_id)&.map(&:target_id) end + def paginate_relationships(method) + @relationships = @user.public_send(method, last_id: params[:last_id]) + @relationships_last_id = @relationships.map(&:id).min + @more_data_available = !@user.public_send(method, last_id: @relationships_last_id, size: 1).count.zero? + end + def hidden_social_graph_redirect return if belongs_to_current_user? || !@user.privacy_hide_social_graph