Skip to content
代码片段 群组 项目
未验证 提交 22ccab7b 编辑于 作者: John Mason's avatar John Mason 提交者: GitLab
浏览文件

Merge branch...

Merge branch '469494-add-support-for-legacy-epic-references-in-workitemsbyreference-query' into 'master' 

Add support for legacy epic references in workItemsByReference query

See merge request https://gitlab.com/gitlab-org/gitlab/-/merge_requests/157787



Merged-by: default avatarJohn Mason <9717668-johnmason@users.noreply.gitlab.com>
Approved-by: default avatarAbhilash Kotte <akotte@gitlab.com>
Approved-by: default avatarJohn Mason <9717668-johnmason@users.noreply.gitlab.com>
Co-authored-by: default avatarEugenia Grieff <egrieff@gitlab.com>
No related branches found
No related tags found
无相关合并请求
...@@ -45,15 +45,20 @@ def resolve_with_lookahead(context_namespace_path: nil, refs: []) ...@@ -45,15 +45,20 @@ def resolve_with_lookahead(context_namespace_path: nil, refs: [])
# rubocop: disable CodeReuse/ActiveRecord -- #references is not an ActiveRecord method # rubocop: disable CodeReuse/ActiveRecord -- #references is not an ActiveRecord method
def find_work_items(references) def find_work_items(references)
# Also check for references with :issue pattern to find legacy issues epic_refs, issue_refs = references.partition { |r| r.match?(/epics|&/) }
item_ids = references_extractor(references).references(:issue, ids_only: true) item_ids = references_extractor(issue_refs)&.references(:work_item, ids_only: true) || []
item_ids << references_extractor(references).references(:work_item, ids_only: true)
WorkItem.id_in(item_ids.flatten) # Also check for references with :issue and :epic patterns to find legacy items
item_ids << references_extractor(issue_refs)&.references(:issue, ids_only: true)
item_ids << references_extractor(epic_refs)&.references(:epic)&.pluck(:issue_id)
WorkItem.id_in(item_ids.flatten.compact)
end end
# rubocop: enable CodeReuse/ActiveRecord # rubocop: enable CodeReuse/ActiveRecord
def references_extractor(refs) def references_extractor(refs)
return unless refs.any?
extractor, analyze_context = extractor, analyze_context =
if container.is_a?(Group) if container.is_a?(Group)
[::Gitlab::ReferenceExtractor.new(nil, context[:current_user]), { group: container }] [::Gitlab::ReferenceExtractor.new(nil, context[:current_user]), { group: container }]
......
...@@ -13,18 +13,38 @@ ...@@ -13,18 +13,38 @@
let_it_be(:work_item_epic1) { create(:work_item, :epic, namespace: public_group) } let_it_be(:work_item_epic1) { create(:work_item, :epic, namespace: public_group) }
let_it_be(:work_item_epic2) { create(:work_item, :epic, namespace: public_group) } let_it_be(:work_item_epic2) { create(:work_item, :epic, namespace: public_group) }
let_it_be(:private_work_item_epic) { create(:work_item, :epic, namespace: private_group) } let_it_be(:private_work_item_epic) { create(:work_item, :epic, namespace: private_group) }
let_it_be(:legacy_epic1) { create(:epic, group: public_group) }
let_it_be(:legacy_epic2) { create(:epic, group: public_group) }
let_it_be(:legacy_issue1) { create(:issue, project: public_project) }
let_it_be(:legacy_issue2) { create(:issue, project: public_project) }
let(:references) do let(:references) do
[ [
task.to_reference(full: true), task.to_reference(full: true),
work_item_epic1.to_reference(full: true), work_item_epic1.to_reference(full: true),
Gitlab::UrlBuilder.build(work_item_epic2), Gitlab::UrlBuilder.build(work_item_epic2),
private_work_item_epic.to_reference(full: true) private_work_item_epic.to_reference(full: true),
Gitlab::UrlBuilder.build(legacy_epic1),
legacy_epic2.to_reference(full: true),
Gitlab::UrlBuilder.build(legacy_issue1),
legacy_issue2.to_reference(full: true)
] ]
end end
before do
stub_licensed_features(epics: true)
end
shared_examples 'response with accessible work items' do shared_examples 'response with accessible work items' do
let(:items) { [work_item_epic2, work_item_epic1, task] } let(:issue_work_item1) { WorkItem.find(legacy_issue1.id) }
let(:issue_work_item2) { WorkItem.find(legacy_issue2.id) }
let(:items) do
[
issue_work_item2, issue_work_item1, legacy_epic2.work_item, legacy_epic1.work_item,
work_item_epic2, work_item_epic1, task
]
end
it_behaves_like 'a working graphql query that returns data' do it_behaves_like 'a working graphql query that returns data' do
before do before do
...@@ -42,22 +62,30 @@ ...@@ -42,22 +62,30 @@
it 'avoids N+1 queries', :use_sql_query_cache do it 'avoids N+1 queries', :use_sql_query_cache do
post_graphql(query, current_user: current_user) # warm up post_graphql(query, current_user: current_user) # warm up
references1 = [task, work_item_epic1, work_item_epic2].map { |item| item.to_reference(full: true) }
control_count = ActiveRecord::QueryRecorder.new(skip_cached: false) do control_count = ActiveRecord::QueryRecorder.new(skip_cached: false) do
post_graphql(query, current_user: current_user) post_graphql(query(refs: references1), current_user: current_user)
end end
expect(graphql_data_at('workItemsByReference', 'nodes').size).to eq(3) expect(graphql_data_at('workItemsByReference', 'nodes').size).to eq(3)
extra_work_items = create_list(:work_item, 3, :epic, namespace: public_group) extra_work_items = create_list(:work_item, 3, :epic, namespace: public_group)
refs = references + extra_work_items.map { |item| item.to_reference(full: true) } references2 = references1 + extra_work_items.map { |item| item.to_reference(full: true) }
expect do expect do
post_graphql(query(refs: refs), current_user: current_user) post_graphql(query(refs: references2), current_user: current_user)
end.not_to exceed_all_query_limit(control_count) end.not_to exceed_all_query_limit(control_count)
expect(graphql_data_at('workItemsByReference', 'nodes').size).to eq(6) expect(graphql_data_at('workItemsByReference', 'nodes').size).to eq(6)
end end
context 'with access to private group' do context 'with access to private group' do
let(:items) { [private_work_item_epic, work_item_epic2, work_item_epic1, task] } let(:items) do
[
issue_work_item2, issue_work_item1, legacy_epic2.work_item, legacy_epic1.work_item,
private_work_item_epic, work_item_epic2, work_item_epic1, task
]
end
before_all do before_all do
private_group.add_guest(current_user) private_group.add_guest(current_user)
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册