summaryrefslogtreecommitdiff
path: root/app/controllers/autocomplete_controller.rb
diff options
context:
space:
mode:
authorSean McGivern <sean@gitlab.com>2017-01-25 14:44:44 +0000
committerSean McGivern <sean@gitlab.com>2017-01-27 15:28:17 +0000
commit2c40a012d63784d1ad91a3629cb1e66ca9ffa96a (patch)
treefa63c2000c81744f711a2ba2f65c615dd1df1f28 /app/controllers/autocomplete_controller.rb
parent65bf7e0d92856d90215ca908751e676393c10618 (diff)
downloadgitlab-ce-2c40a012d63784d1ad91a3629cb1e66ca9ffa96a.tar.gz
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).
Diffstat (limited to 'app/controllers/autocomplete_controller.rb')
-rw-r--r--app/controllers/autocomplete_controller.rb5
1 files changed, 2 insertions, 3 deletions
diff --git a/app/controllers/autocomplete_controller.rb b/app/controllers/autocomplete_controller.rb
index 6db4e1dc1bc..d7a45bacd35 100644
--- a/app/controllers/autocomplete_controller.rb
+++ b/app/controllers/autocomplete_controller.rb
@@ -18,15 +18,14 @@ class AutocompleteController < ApplicationController
if params[:search].blank?
# Include current user if available to filter by "Me"
if params[:current_user].present? && current_user
+ @users = @users.where.not(id: current_user.id)
@users = [current_user, *@users]
end
if params[:author_id].present?
author = User.find_by_id(params[:author_id])
- @users = [author, *@users] if author
+ @users = [author, *@users].uniq if author
end
-
- @users.uniq!
end
render json: @users, only: [:name, :username, :id], methods: [:avatar_url]