Commit 7cdf20af authored by Alexandru Croitor's avatar Alexandru Croitor

Introduce an optimized labels query on group transfer

This MR enables the optimized query for fetching issue and
merge request labels to be transfered when a group or a
project is transfered.

Changelog: performance
parent 3ad6b9cc
...@@ -50,32 +50,17 @@ module Labels ...@@ -50,32 +50,17 @@ module Labels
# rubocop: disable CodeReuse/ActiveRecord # rubocop: disable CodeReuse/ActiveRecord
def group_labels_applied_to_issues def group_labels_applied_to_issues
@labels_applied_to_issues ||= if use_optimized_group_labels_query? @labels_applied_to_issues ||= Label.joins(:issues)
Label.joins(:issues) .joins("INNER JOIN namespaces on namespaces.id = labels.group_id AND namespaces.type = 'Group'" )
.joins("INNER JOIN namespaces on namespaces.id = labels.group_id AND namespaces.type = 'Group'" ) .where(issues: { project_id: project.id }).reorder(nil)
.where(issues: { project_id: project.id }).reorder(nil)
else
Label.joins(:issues).where(
issues: { project_id: project.id },
labels: { group_id: old_group.self_and_ancestors }
)
end
end end
# rubocop: enable CodeReuse/ActiveRecord # rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord # rubocop: disable CodeReuse/ActiveRecord
def group_labels_applied_to_merge_requests def group_labels_applied_to_merge_requests
@labels_applied_to_mrs ||= if use_optimized_group_labels_query? @labels_applied_to_mrs ||= Label.joins(:merge_requests)
Label.joins(:merge_requests) .joins("INNER JOIN namespaces on namespaces.id = labels.group_id AND namespaces.type = 'Group'" )
.joins("INNER JOIN namespaces on namespaces.id = labels.group_id AND namespaces.type = 'Group'" ) .where(merge_requests: { target_project_id: project.id }).reorder(nil)
.where(merge_requests: { target_project_id: project.id }).reorder(nil)
else
Label.joins(:merge_requests)
.where(
merge_requests: { target_project_id: project.id },
labels: { group_id: old_group.self_and_ancestors }
)
end
end end
# rubocop: enable CodeReuse/ActiveRecord # rubocop: enable CodeReuse/ActiveRecord
...@@ -99,9 +84,5 @@ module Labels ...@@ -99,9 +84,5 @@ module Labels
.update_all(label_id: new_label_id) .update_all(label_id: new_label_id)
end end
# rubocop: enable CodeReuse/ActiveRecord # rubocop: enable CodeReuse/ActiveRecord
def use_optimized_group_labels_query?
Feature.enabled?(:use_optimized_group_labels_query, project.root_namespace, default_enabled: :yaml)
end
end end
end end
---
name: use_optimized_group_labels_query
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/73501
rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/344957
milestone: '14.5'
type: development
group: group::workspace
default_enabled: true
...@@ -109,15 +109,5 @@ RSpec.describe Labels::TransferService do ...@@ -109,15 +109,5 @@ RSpec.describe Labels::TransferService do
end end
end end
context 'with use_optimized_group_labels_query FF on' do it_behaves_like 'transfer labels'
it_behaves_like 'transfer labels'
end
context 'with use_optimized_group_labels_query FF off' do
before do
stub_feature_flags(use_optimized_group_labels_query: false)
end
it_behaves_like 'transfer labels'
end
end end
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