De-duplicate relationship pagination logic

This commit is contained in:
Karina Kwiatek 2023-01-31 13:59:05 +01:00
parent 83eeabb525
commit 8520dbc4b9
1 changed files with 8 additions and 6 deletions

View File

@ -17,9 +17,7 @@ class UserController < ApplicationController
end end
def followers def followers
@relationships = @user.cursored_follower_relationships(last_id: params[:last_id]) paginate_relationships(:cursored_follower_relationships)
@relationships_last_id = @relationships.map(&:id).min
@more_data_available = !@user.cursored_follower_relationships(last_id: @relationships_last_id, size: 1).count.zero?
@users = @relationships.map(&:source) @users = @relationships.map(&:source)
own_followings = find_own_relationships(current_user&.active_follow_relationships) own_followings = find_own_relationships(current_user&.active_follow_relationships)
own_blocks = find_own_relationships(current_user&.active_block_relationships) own_blocks = find_own_relationships(current_user&.active_block_relationships)
@ -31,9 +29,7 @@ class UserController < ApplicationController
end end
def followings def followings
@relationships = @user.cursored_following_relationships(last_id: params[:last_id]) paginate_relationships(:cursored_following_relationships)
@relationships_last_id = @relationships.map(&:id).min
@more_data_available = !@user.cursored_following_relationships(last_id: @relationships_last_id, size: 1).count.zero?
@users = @relationships.map(&:target) @users = @relationships.map(&:target)
own_followings = find_own_relationships(current_user&.active_follow_relationships) own_followings = find_own_relationships(current_user&.active_follow_relationships)
own_blocks = find_own_relationships(current_user&.active_block_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) relationships.where(target_id: @users.map(&:id))&.select(:target_id)&.map(&:target_id)
end 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 def hidden_social_graph_redirect
return if belongs_to_current_user? || !@user.privacy_hide_social_graph return if belongs_to_current_user? || !@user.privacy_hide_social_graph