Commit 3bf36298 authored by Heinrich Lee Yu's avatar Heinrich Lee Yu

Fix duplicate author showing up in autocomplete

The author was already turned into a hash before calling uniq so the
duplicates weren't filtered out.

This also adds the status preloading to the author so that it's included
when we batch load user statuses.
parent ba7126ef
......@@ -13,7 +13,9 @@ module Users
def noteable_owner
return [] unless noteable && noteable.author.present?
[user_as_hash(noteable.author)]
[noteable.author].tap do |users|
preload_status(users)
end
end
def participants_in_noteable
......
......@@ -4,45 +4,55 @@ require 'spec_helper'
RSpec.describe Projects::ParticipantsService do
describe '#execute' do
let(:user) { create(:user) }
let(:project) { create(:project, :public) }
let(:noteable) { create(:issue, project: project) }
let_it_be(:user) { create(:user) }
let_it_be(:project) { create(:project, :public) }
let_it_be(:noteable) { create(:issue, project: project) }
before_all do
project.add_developer(user)
end
def run_service
described_class.new(project, user).execute(noteable)
end
before do
project.add_developer(user)
context 'N+1 checks' do
before do
run_service # warmup, runs table cache queries and create queries
BatchLoader::Executor.clear_current
end
run_service # warmup, runs table cache queries and create queries
BatchLoader::Executor.clear_current
end
it 'avoids N+1 UserDetail queries' do
project.add_developer(create(:user))
it 'avoids N+1 UserDetail queries' do
project.add_developer(create(:user))
control_count = ActiveRecord::QueryRecorder.new { run_service.to_a }.count
control_count = ActiveRecord::QueryRecorder.new { run_service.to_a }.count
BatchLoader::Executor.clear_current
BatchLoader::Executor.clear_current
project.add_developer(create(:user, status: build(:user_status, availability: :busy)))
project.add_developer(create(:user, status: build(:user_status, availability: :busy)))
expect { run_service.to_a }.not_to exceed_query_limit(control_count)
end
expect { run_service.to_a }.not_to exceed_query_limit(control_count)
end
it 'avoids N+1 groups queries' do
group_1 = create(:group)
group_1.add_owner(user)
it 'avoids N+1 groups queries' do
group_1 = create(:group)
group_1.add_owner(user)
control_count = ActiveRecord::QueryRecorder.new { run_service }.count
control_count = ActiveRecord::QueryRecorder.new { run_service }.count
BatchLoader::Executor.clear_current
BatchLoader::Executor.clear_current
group_2 = create(:group)
group_2.add_owner(user)
expect { run_service }.not_to exceed_query_limit(control_count)
end
end
group_2 = create(:group)
group_2.add_owner(user)
it 'does not return duplicate author' do
participants = run_service
expect { run_service }.not_to exceed_query_limit(control_count)
expect(participants.count { |p| p[:username] == noteable.author.username }).to eq 1
end
describe 'group items' do
......
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