From 17abc148d3a48495617c05e01c1ee911af4bb5a1 Mon Sep 17 00:00:00 2001 From: Sean McGivern Date: Wed, 25 Jan 2017 14:44:44 +0000 Subject: 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). --- app/controllers/autocomplete_controller.rb | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/app/controllers/autocomplete_controller.rb b/app/controllers/autocomplete_controller.rb index 6db4e1dc1bc..b79ca034c5b 100644 --- a/app/controllers/autocomplete_controller.rb +++ b/app/controllers/autocomplete_controller.rb @@ -18,15 +18,13 @@ class AutocompleteController < ApplicationController if params[:search].blank? # Include current user if available to filter by "Me" if params[:current_user].present? && current_user - @users = [current_user, *@users] + @users = [current_user, *@users].uniq 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] -- cgit v1.2.1