Commit 50ae2c8e authored by Sean McGivern's avatar Sean McGivern

Merge branch 'remove-ff-in-count-users-by-group' into 'master'

Remove optimized_count_users_by_group_id FF

See merge request gitlab-org/gitlab!36953
parents d90364dd 9b8d1fd2
......@@ -17,14 +17,7 @@ class GroupMember < Member
scope :of_groups, ->(groups) { where(source_id: groups.select(:id)) }
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
scope :count_users_by_group_id, -> { group(:source_id).count }
after_create :update_two_factor_requirement, unless: :invite?
after_destroy :update_two_factor_requirement, unless: :invite?
......
---
title: Remove optimized_count_users_by_group_id feature flag
merge_request: 36953
author:
type: performance
......@@ -4,50 +4,18 @@ require 'spec_helper'
RSpec.describe GroupMember do
context 'scopes' do
shared_examples '.count_users_by_group_id' do
it 'counts users by group ID' do
user_1 = create(:user)
user_2 = create(:user)
group_1 = create(:group)
group_2 = create(:group)
group_1.add_owner(user_1)
group_1.add_owner(user_2)
group_2.add_owner(user_1)
expect(described_class.count_users_by_group_id).to eq(group_1.id => 2,
group_2.id => 1)
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
it 'counts users by group ID' do
user_1 = create(:user)
user_2 = create(:user)
group_1 = create(:group)
group_2 = create(:group)
group_1.add_owner(user_1)
group_1.add_owner(user_2)
group_2.add_owner(user_1)
expect(described_class.count_users_by_group_id).to eq(group_1.id => 2,
group_2.id => 1)
end
describe '.of_ldap_type' 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