Commit ad58bc2b authored by James Fargher's avatar James Fargher

Merge branch 'optimize-autocomplete-sources-controller' into 'master'

Optimize participants list

See merge request gitlab-org/gitlab!33981
parents 963966c1 7e3c5aa3
...@@ -16,9 +16,16 @@ class GroupMember < Member ...@@ -16,9 +16,16 @@ class GroupMember < Member
default_scope { where(source_type: SOURCE_TYPE) } # rubocop:disable Cop/DefaultScope default_scope { where(source_type: SOURCE_TYPE) } # rubocop:disable Cop/DefaultScope
scope :of_groups, ->(groups) { where(source_id: groups.select(:id)) } scope :of_groups, ->(groups) { where(source_id: groups.select(:id)) }
scope :count_users_by_group_id, -> { joins(:user).group(:source_id).count }
scope :of_ldap_type, -> { where(ldap: true) } scope :of_ldap_type, -> { where(ldap: true) }
scope :count_users_by_group_id, -> do
if Feature.enabled?(:optimized_count_users_by_group_id)
group(:source_id).count
else
joins(:user).group(:source_id).count
end
end
after_create :update_two_factor_requirement, unless: :invite? after_create :update_two_factor_requirement, unless: :invite?
after_destroy :update_two_factor_requirement, unless: :invite? after_destroy :update_two_factor_requirement, unless: :invite?
......
...@@ -4,7 +4,7 @@ require 'spec_helper' ...@@ -4,7 +4,7 @@ require 'spec_helper'
describe GroupMember do describe GroupMember do
context 'scopes' do context 'scopes' do
describe '.count_users_by_group_id' do shared_examples '.count_users_by_group_id' do
it 'counts users by group ID' do it 'counts users by group ID' do
user_1 = create(:user) user_1 = create(:user)
user_2 = create(:user) user_2 = create(:user)
...@@ -20,6 +20,36 @@ describe GroupMember do ...@@ -20,6 +20,36 @@ describe GroupMember do
end end
end end
describe '.count_users_by_group_id with optimized_count_users_by_group_id feature flag on' do
before do
stub_feature_flags(optimized_count_users_by_group_id: true)
end
it_behaves_like '.count_users_by_group_id'
it 'does not JOIN users' do
scope = described_class.all
expect(scope).not_to receive(:joins).with(:user)
scope.count_users_by_group_id
end
end
describe '.count_users_by_group_id with optimized_count_users_by_group_id feature flag off' do
before do
stub_feature_flags(optimized_count_users_by_group_id: false)
end
it_behaves_like '.count_users_by_group_id'
it 'does JOIN users' do
scope = described_class.all
expect(scope).to receive(:joins).with(:user).and_call_original
scope.count_users_by_group_id
end
end
describe '.of_ldap_type' do describe '.of_ldap_type' do
it 'returns ldap type users' do it 'returns ldap type users' do
group_member = create(:group_member, :ldap) group_member = create(:group_member, :ldap)
......
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