Fix inefficient queries in “Follows and followers” as well as several admin pages (#27116)
This commit is contained in:
		
							parent
							
								
									88fa8e710a
								
							
						
					
					
						commit
						1bd7455d81
					
				| 
						 | 
				
			
			@ -62,13 +62,13 @@ class RelationshipFilter
 | 
			
		|||
  def relationship_scope(value)
 | 
			
		||||
    case value
 | 
			
		||||
    when 'following'
 | 
			
		||||
      account.following.eager_load(:account_stat).reorder(nil)
 | 
			
		||||
      account.following.includes(:account_stat).reorder(nil)
 | 
			
		||||
    when 'followed_by'
 | 
			
		||||
      account.followers.eager_load(:account_stat).reorder(nil)
 | 
			
		||||
      account.followers.includes(:account_stat).reorder(nil)
 | 
			
		||||
    when 'mutual'
 | 
			
		||||
      account.followers.eager_load(:account_stat).reorder(nil).merge(Account.where(id: account.following))
 | 
			
		||||
      account.followers.includes(:account_stat).reorder(nil).merge(Account.where(id: account.following))
 | 
			
		||||
    when 'invited'
 | 
			
		||||
      Account.joins(user: :invite).merge(Invite.where(user: account.user)).eager_load(:account_stat).reorder(nil)
 | 
			
		||||
      Account.joins(user: :invite).merge(Invite.where(user: account.user)).includes(:account_stat).reorder(nil)
 | 
			
		||||
    else
 | 
			
		||||
      raise Mastodon::InvalidParameterError, "Unknown relationship: #{value}"
 | 
			
		||||
    end
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue