Commit 54185a48 authored by Saikat Sarkar's avatar Saikat Sarkar

Merge branch 'remove-optimize-safe-find-or-create-feature-flag' into 'master'

Remove optimize_safe_find_or_create_by FF

See merge request gitlab-org/gitlab!68827
parents f79559cd 54715b73
...@@ -64,14 +64,6 @@ class ApplicationRecord < ActiveRecord::Base ...@@ -64,14 +64,6 @@ class ApplicationRecord < ActiveRecord::Base
end end
def self.safe_find_or_create_by(*args, &block) def self.safe_find_or_create_by(*args, &block)
return optimized_safe_find_or_create_by(*args, &block) if Feature.enabled?(:optimize_safe_find_or_create_by, default_enabled: :yaml)
safe_ensure_unique(retries: 1) do # rubocop:disable Performance/ActiveRecordSubtransactionMethods
find_or_create_by(*args, &block)
end
end
def self.optimized_safe_find_or_create_by(*args, &block)
record = find_by(*args) record = find_by(*args)
return record if record.present? return record if record.present?
......
---
name: optimize_safe_find_or_create_by
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/68458
rollout_issue_url:
milestone: '14.3'
type: development
group: group::database
default_enabled: false
...@@ -39,7 +39,7 @@ RSpec.describe ApplicationRecord do ...@@ -39,7 +39,7 @@ RSpec.describe ApplicationRecord do
let(:suggestion_attributes) { attributes_for(:suggestion).merge!(note_id: note.id) } let(:suggestion_attributes) { attributes_for(:suggestion).merge!(note_id: note.id) }
shared_examples '.safe_find_or_create_by' do describe '.safe_find_or_create_by' do
it 'creates the suggestion avoiding race conditions' do it 'creates the suggestion avoiding race conditions' do
existing_suggestion = double(:Suggestion) existing_suggestion = double(:Suggestion)
...@@ -63,7 +63,7 @@ RSpec.describe ApplicationRecord do ...@@ -63,7 +63,7 @@ RSpec.describe ApplicationRecord do
end end
end end
shared_examples '.safe_find_or_create_by!' do describe '.safe_find_or_create_by!' do
it 'creates a record using safe_find_or_create_by' do it 'creates a record using safe_find_or_create_by' do
expect(Suggestion.safe_find_or_create_by!(suggestion_attributes)) expect(Suggestion.safe_find_or_create_by!(suggestion_attributes))
.to be_a(Suggestion) .to be_a(Suggestion)
...@@ -88,24 +88,6 @@ RSpec.describe ApplicationRecord do ...@@ -88,24 +88,6 @@ RSpec.describe ApplicationRecord do
.to raise_error(ActiveRecord::RecordNotFound) .to raise_error(ActiveRecord::RecordNotFound)
end end
end end
context 'when optimized_safe_find_or_create_by is enabled' do
before do
stub_feature_flags(optimized_safe_find_or_create_by: true)
end
it_behaves_like '.safe_find_or_create_by'
it_behaves_like '.safe_find_or_create_by!'
end
context 'when optimized_safe_find_or_create_by is disabled' do
before do
stub_feature_flags(optimized_safe_find_or_create_by: false)
end
it_behaves_like '.safe_find_or_create_by'
it_behaves_like '.safe_find_or_create_by!'
end
end end
describe '.underscore' do describe '.underscore' do
......
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