Commit fa5a9902 authored by Jan Provaznik's avatar Jan Provaznik

Merge branch '194104-part-2' into 'master'

Fix another repeating queries

See merge request gitlab-org/gitlab!60718
parents f2e87cba aa7a3d48
...@@ -6,7 +6,7 @@ module Labels ...@@ -6,7 +6,7 @@ module Labels
@current_user = current_user @current_user = current_user
@parent = parent @parent = parent
@available_labels = params.delete(:available_labels) @available_labels = params.delete(:available_labels)
@existing_labels_by_title = params.delete(:existing_labels_by_title) || {} @existing_labels_by_title = params.delete(:existing_labels_by_title)
@params = params.dup.with_indifferent_access @params = params.dup.with_indifferent_access
end end
...@@ -45,7 +45,9 @@ module Labels ...@@ -45,7 +45,9 @@ module Labels
# rubocop: disable CodeReuse/ActiveRecord # rubocop: disable CodeReuse/ActiveRecord
def find_existing_label(title) def find_existing_label(title)
existing_labels_by_title[title] || available_labels.find_by(title: title) return existing_labels_by_title[title] if existing_labels_by_title
available_labels.find_by(title: title)
end end
# rubocop: enable CodeReuse/ActiveRecord # rubocop: enable CodeReuse/ActiveRecord
......
---
title: Fix repeating SQL queries when changing labels for a resource.
merge_request: 60718
author:
type: performance
...@@ -115,8 +115,6 @@ module API ...@@ -115,8 +115,6 @@ module API
at_least_one_of :title, :description, :start_date_fixed, :start_date_is_fixed, :due_date_fixed, :due_date_is_fixed, :labels, :add_labels, :remove_labels, :state_event, :confidential at_least_one_of :title, :description, :start_date_fixed, :start_date_is_fixed, :due_date_fixed, :due_date_is_fixed, :labels, :add_labels, :remove_labels, :state_event, :confidential
end end
put ':id/(-/)epics/:epic_iid' do put ':id/(-/)epics/:epic_iid' do
Gitlab::QueryLimiting.disable!('https://gitlab.com/gitlab-org/gitlab/issues/194104')
authorize_can_admin_epic! authorize_can_admin_epic!
# Setting updated_at is allowed only for admins and owners # Setting updated_at is allowed only for admins and owners
......
...@@ -25,6 +25,35 @@ RSpec.describe Labels::FindOrCreateService do ...@@ -25,6 +25,35 @@ RSpec.describe Labels::FindOrCreateService do
project.add_developer(user) project.add_developer(user)
end end
context 'when existing_labels_by_title is provided' do
let(:preloaded_label) { build(:label, title: 'Security') }
before do
params.merge!(
existing_labels_by_title: {
'Security' => preloaded_label
})
end
context 'when label exists' do
it 'returns preloaded label' do
expect(service.execute).to eq preloaded_label
end
end
context 'when label does not exists' do
before do
params[:title] = 'Audit'
end
it 'does not generates additional label search' do
service.execute
expect(LabelsFinder).not_to receive(:new)
end
end
end
context 'when label does not exist at group level' do context 'when label does not exist at group level' do
it 'creates a new label at project level' do it 'creates a new label at project level' do
expect { service.execute }.to change(project.labels, :count).by(1) expect { service.execute }.to change(project.labels, :count).by(1)
......
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