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).
Makes the worst case for https://gitlab.com/gitlab-org/gitlab-ce/issues/27085 better.
Merge request reports
Activity
Makes sense, thanks @smcgivern!
enabled an automatic merge when the pipeline for 17abc148 succeeds
enabled an automatic merge when the pipeline for 17abc148 succeeds
mentioned in issue #27147 (closed)
18 18 if params[:search].blank? 19 19 # Include current user if available to filter by "Me" 20 20 if params[:current_user].present? && current_user 21 @users = [current_user, *@users] 21 @users = [current_user, *@users].uniq @smcgivern Since the goal of the
uniq
seems to be to make surecurrent_user
doesn't occur twice, how explicitly removingcurrent_user
from@users
? Two options:# 1 @users = [current_user, *@users.delete(current_user)] # 2 @users = @users.where.not(id: current_user.id) @users = [current_user, *@users]
I prefer 2, since 1, could have us end up showing an inconsistent number of users depending on whether
current_user
occurs on the first page.I don't have a problem with either, but showing an inconsistent number of users has been happening for over a year
Also, for option 2, that's trickier when we're passing an
author_id
, because if that user ID doesn't exist, we want 20 'other' users, and if that user ID does exist, we want 19 'other' users. We could addCASE WHEN id = :author_id THEN 0 ELSE 1 AS order
, and thenORDER BY order, name
, but realistically I have no problem with doing this in Ruby to avoid theSELECT DISTINCT
@smcgivern I don't care all too much about the number of users, but if we can skip a
uniq
when we know exactly which element we want to remove, I think we should!I've done this for the
current_user
case. For theauthor_id
case, because you can passcurrent_user
andauthor_id
, I don't think we should do this, as we wouldn't have a relation. I'm pretty sure that we don't do that, but this isn't very well-specified, and all I really want to do here is fix that one query.This fails in EE on the mirror page, because
@users
is an array at this point
assigned to @smcgivern
assigned to @DouweM
assigned to @smcgivern
assigned to @DouweM
enabled an automatic merge when the pipeline for 2c40a012 succeeds
mentioned in commit 916fae3a
mentioned in issue #27400 (closed)