Skip to content
代码片段 群组 项目
提交 d5bd7f1e 编辑于 作者: Nicolas Dular's avatar Nicolas Dular
浏览文件

Run validation only for synced epics

We can trim down the number of sidekiq jobs spawned by checking if the
epic also has a synced work item.
In addition we can use the new `actor_from_id` method to not query the
group but still check the feature flag.
上级 564bad23
No related branches found
No related tags found
无相关合并请求
...@@ -112,6 +112,7 @@ module Epic ...@@ -112,6 +112,7 @@ module Epic
end end
scope :with_work_item, -> { preload(:work_item) } scope :with_work_item, -> { preload(:work_item) }
scope :has_work_item, -> { where.not(issue_id: nil) }
scope :within_timeframe, -> (start_date, end_date) do scope :within_timeframe, -> (start_date, end_date) do
epics = ::Epic.arel_table epics = ::Epic.arel_table
......
...@@ -78,12 +78,14 @@ def subscribe_to_epic_events(store) ...@@ -78,12 +78,14 @@ def subscribe_to_epic_events(store)
store.subscribe ::WorkItems::ValidateEpicWorkItemSyncWorker, store.subscribe ::WorkItems::ValidateEpicWorkItemSyncWorker,
to: ::Epics::EpicCreatedEvent, to: ::Epics::EpicCreatedEvent,
if: ->(event) { if: ->(event) {
::Feature.enabled?(:validate_epic_work_item_sync, ::Group.find_by_id(event.data[:group_id])) ::Feature.enabled?(:validate_epic_work_item_sync, ::Group.actor_from_id(event.data[:group_id])) &&
::Epic.has_work_item.id_in(event.data[:id]).exists?
} }
store.subscribe ::WorkItems::ValidateEpicWorkItemSyncWorker, store.subscribe ::WorkItems::ValidateEpicWorkItemSyncWorker,
to: ::Epics::EpicUpdatedEvent, to: ::Epics::EpicUpdatedEvent,
if: ->(event) { if: ->(event) {
::Feature.enabled?(:validate_epic_work_item_sync, ::Group.find_by_id(event.data[:group_id])) ::Feature.enabled?(:validate_epic_work_item_sync, ::Group.actor_from_id(event.data[:group_id])) &&
::Epic.has_work_item.id_in(event.data[:id]).exists?
} }
end end
end end
......
...@@ -137,6 +137,15 @@ ...@@ -137,6 +137,15 @@
expect(described_class.from_id(epic2.id)).to match_array([epic2, epic3]) expect(described_class.from_id(epic2.id)).to match_array([epic2, epic3])
end end
end end
describe '.has_work_item' do
let_it_be(:epic_with_work_item) { create(:epic, :with_synced_work_item) }
let_it_be(:epic_without_work_item) { create(:epic) }
it 'returns only epics with a work item' do
expect(described_class.has_work_item).to match_array([epic_with_work_item])
end
end
end end
describe 'validations' do describe 'validations' do
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
RSpec.describe WorkItems::ValidateEpicWorkItemSyncWorker, feature_category: :team_planning do RSpec.describe WorkItems::ValidateEpicWorkItemSyncWorker, feature_category: :team_planning do
let_it_be(:group) { create(:group) } let_it_be(:group) { create(:group) }
let_it_be_with_reload(:epic) { create(:epic, group: group) } let_it_be_with_reload(:epic) { create(:epic, :with_synced_work_item, group: group) }
let(:data) { { id: epic.id, group_id: group.id } } let(:data) { { id: epic.id, group_id: group.id } }
let(:epic_created_event) { Epics::EpicCreatedEvent.new(data: data) } let(:epic_created_event) { Epics::EpicCreatedEvent.new(data: data) }
...@@ -39,6 +39,8 @@ ...@@ -39,6 +39,8 @@
end end
context 'when epic has no associated work item' do context 'when epic has no associated work item' do
let_it_be_with_reload(:epic) { create(:epic, group: group) }
it 'does not log anything or tries to create a diff' do it 'does not log anything or tries to create a diff' do
expect(Gitlab::EpicWorkItemSync::Logger).not_to receive(:warn) expect(Gitlab::EpicWorkItemSync::Logger).not_to receive(:warn)
expect(Gitlab::EpicWorkItemSync::Diff).not_to receive(:new) expect(Gitlab::EpicWorkItemSync::Diff).not_to receive(:new)
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册