Commit 2c40a012 authored by Sean McGivern's avatar Sean McGivern

Don't call `#uniq` on a relation

When there was no project, no search, and no current user or author
param, the AutocompleteController would call `#uniq!` on a relation
instead of an array. This performed the less-efficient `SELECT DISTINCT`
when it wasn't even needed (because the query wouldn't return duplicates
anyway - duplicates were only added by putting a user on top of the
list).
parent 65bf7e0d
...@@ -18,15 +18,14 @@ class AutocompleteController < ApplicationController ...@@ -18,15 +18,14 @@ class AutocompleteController < ApplicationController
if params[:search].blank? if params[:search].blank?
# Include current user if available to filter by "Me" # Include current user if available to filter by "Me"
if params[:current_user].present? && current_user if params[:current_user].present? && current_user
@users = @users.where.not(id: current_user.id)
@users = [current_user, *@users] @users = [current_user, *@users]
end end
if params[:author_id].present? if params[:author_id].present?
author = User.find_by_id(params[:author_id]) author = User.find_by_id(params[:author_id])
@users = [author, *@users] if author @users = [author, *@users].uniq if author
end end
@users.uniq!
end end
render json: @users, only: [:name, :username, :id], methods: [:avatar_url] render json: @users, only: [:name, :username, :id], methods: [:avatar_url]
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment