mirror of
https://github.com/Retrospring/retrospring.git
synced 2025-02-13 21:33:20 +01:00
Prevent 𝑛+1 on follower/following lists
This commit is contained in:
parent
2008fe28fa
commit
1b6eafd2d1
2 changed files with 14 additions and 2 deletions
|
@ -21,6 +21,7 @@ class UserController < ApplicationController
|
||||||
@relationships_last_id = @relationships.map(&:id).min
|
@relationships_last_id = @relationships.map(&:id).min
|
||||||
@more_data_available = !@user.cursored_follower_relationships(last_id: @relationships_last_id, size: 1).count.zero?
|
@more_data_available = !@user.cursored_follower_relationships(last_id: @relationships_last_id, size: 1).count.zero?
|
||||||
@users = @relationships.map(&:source)
|
@users = @relationships.map(&:source)
|
||||||
|
find_own_relationships
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html { render "show_follow", locals: { type: :follower } }
|
format.html { render "show_follow", locals: { type: :follower } }
|
||||||
|
@ -33,6 +34,7 @@ class UserController < ApplicationController
|
||||||
@relationships_last_id = @relationships.map(&:id).min
|
@relationships_last_id = @relationships.map(&:id).min
|
||||||
@more_data_available = !@user.cursored_following_relationships(last_id: @relationships_last_id, size: 1).count.zero?
|
@more_data_available = !@user.cursored_following_relationships(last_id: @relationships_last_id, size: 1).count.zero?
|
||||||
@users = @relationships.map(&:target)
|
@users = @relationships.map(&:target)
|
||||||
|
find_own_relationships
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html { render "show_follow", locals: { type: :friend } }
|
format.html { render "show_follow", locals: { type: :friend } }
|
||||||
|
@ -69,6 +71,16 @@ class UserController < ApplicationController
|
||||||
@user = User.where("LOWER(screen_name) = ?", params[:username].downcase).includes(:profile).first!
|
@user = User.where("LOWER(screen_name) = ?", params[:username].downcase).includes(:profile).first!
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Checks which of the displayed users are followed or blocked by the current user
|
||||||
|
#
|
||||||
|
# This prevents 𝑛+1 queries.
|
||||||
|
def find_own_relationships
|
||||||
|
return unless user_signed_in?
|
||||||
|
|
||||||
|
@own_followings = current_user.active_follow_relationships.where(target_id: @users.map(&:id)).select(:target_id).map(&:target_id)
|
||||||
|
@own_blocks = current_user.active_block_relationships.where(target_id: @users.map(&:id)).select(:target_id).map(&:target_id)
|
||||||
|
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
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
%a.btn.btn-dark{ href: settings_profile_path } Edit profile
|
%a.btn.btn-dark{ href: settings_profile_path } Edit profile
|
||||||
- elsif user_signed_in?
|
- elsif user_signed_in?
|
||||||
.d-grid.gap-2
|
.d-grid.gap-2
|
||||||
- if current_user.following? user
|
- if @own_followings.include?(user.id)
|
||||||
%button.btn.btn-primary{ type: :button, name: 'user-action', data: { action: :unfollow, type: type, target: user.screen_name } }
|
%button.btn.btn-primary{ type: :button, name: 'user-action', data: { action: :unfollow, type: type, target: user.screen_name } }
|
||||||
= t("voc.unfollow")
|
= t("voc.unfollow")
|
||||||
- else
|
- else
|
||||||
|
@ -19,7 +19,7 @@
|
||||||
%a.dropdown-item.d-block.d-sm-none{ href: '#', data: { bs_target: '#modal-list-memberships', bs_toggle: :modal } }
|
%a.dropdown-item.d-block.d-sm-none{ href: '#', data: { bs_target: '#modal-list-memberships', bs_toggle: :modal } }
|
||||||
%i.fa.fa-list.fa-fw
|
%i.fa.fa-list.fa-fw
|
||||||
= t(".list")
|
= t(".list")
|
||||||
- if current_user.blocking?(user)
|
- if @own_blocks.include?(user.id)
|
||||||
%a.dropdown-item{ href: '#', data: { action: :unblock, target: user.screen_name } }
|
%a.dropdown-item{ href: '#', data: { action: :unblock, target: user.screen_name } }
|
||||||
%i.fa.fa-minus-circle.fa-fw
|
%i.fa.fa-minus-circle.fa-fw
|
||||||
%span.pe-none= t("voc.unblock")
|
%span.pe-none= t("voc.unblock")
|
||||||
|
|
Loading…
Reference in a new issue