Skip to content

Commit

Permalink
Fix inefficient queries in “Follows and followers” as well as several…
Browse files Browse the repository at this point in the history
… admin pages (#27116)
  • Loading branch information
ClearlyClaire committed Oct 10, 2023
1 parent 89f98f4 commit e5772c9
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions app/models/relationship_filter.rb
Expand Up @@ -60,13 +60,13 @@ def scope_for(key, value)
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
Expand Down

0 comments on commit e5772c9

Please sign in to comment.