Commit bb5af954 authored by Adam Hegyi's avatar Adam Hegyi Committed by Mayra Cabrera

Improve .groups_user_can_read_epics performance

parent 69c31c11
...@@ -196,7 +196,13 @@ module EE ...@@ -196,7 +196,13 @@ module EE
end end
def groups_user_can_read_epics(epics, user) def groups_user_can_read_epics(epics, user)
groups = ::Group.where(id: epics.select(:group_id)) groups = if ::Feature.enabled?(:optimized_groups_user_can_read_epics_method)
epics_query = epics.select(:group_id)
::Group.joins("INNER JOIN (#{epics_query.to_sql}) as epics on epics.group_id = namespaces.id")
else
::Group.where(id: epics.select(:group_id))
end
groups = ::Gitlab::GroupPlansPreloader.new.preload(groups) groups = ::Gitlab::GroupPlansPreloader.new.preload(groups)
DeclarativePolicy.user_scope do DeclarativePolicy.user_scope do
......
...@@ -101,7 +101,7 @@ describe Epic do ...@@ -101,7 +101,7 @@ describe Epic do
end end
end end
describe '.groups_user_can_read_epics' do shared_examples '.groups_user_can_read_epics examples' do
let_it_be(:private_group) { create(:group, :private) } let_it_be(:private_group) { create(:group, :private) }
let_it_be(:epic) { create(:epic, group: private_group) } let_it_be(:epic) { create(:epic, group: private_group) }
...@@ -141,6 +141,24 @@ describe Epic do ...@@ -141,6 +141,24 @@ describe Epic do
end end
end end
describe '.groups_user_can_read_epics' do
context 'with `optimized_groups_user_can_read_epics_method` feature flag enabled' do
before do
stub_feature_flags(optimized_groups_user_can_read_epics_method: true)
end
include_examples '.groups_user_can_read_epics examples'
end
context 'with `optimized_groups_user_can_read_epics_method` feature flag disabled' do
before do
stub_feature_flags(optimized_groups_user_can_read_epics_method: false)
end
include_examples '.groups_user_can_read_epics examples'
end
end
describe '#valid_parent?' do describe '#valid_parent?' do
context 'basic checks' do context 'basic checks' do
let(:epic) { build(:epic, group: group) } let(:epic) { build(:epic, group: group) }
......
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