Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
b7b29551
Commit
b7b29551
authored
Aug 25, 2021
by
GitLab Bot
Browse files
Options
Browse Files
Download
Plain Diff
Automatic merge of gitlab-org/gitlab master
parents
1de95047
54185a48
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
2 additions
and
36 deletions
+2
-36
app/models/application_record.rb
app/models/application_record.rb
+0
-8
config/feature_flags/development/optimize_safe_find_or_create_by.yml
...ure_flags/development/optimize_safe_find_or_create_by.yml
+0
-8
spec/models/application_record_spec.rb
spec/models/application_record_spec.rb
+2
-20
No files found.
app/models/application_record.rb
View file @
b7b29551
...
...
@@ -64,14 +64,6 @@ class ApplicationRecord < ActiveRecord::Base
end
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
)
return
record
if
record
.
present?
...
...
config/feature_flags/development/optimize_safe_find_or_create_by.yml
deleted
100644 → 0
View file @
1de95047
---
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
spec/models/application_record_spec.rb
View file @
b7b29551
...
...
@@ -39,7 +39,7 @@ RSpec.describe ApplicationRecord do
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
existing_suggestion
=
double
(
:Suggestion
)
...
...
@@ -63,7 +63,7 @@ RSpec.describe ApplicationRecord do
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
expect
(
Suggestion
.
safe_find_or_create_by!
(
suggestion_attributes
))
.
to
be_a
(
Suggestion
)
...
...
@@ -88,24 +88,6 @@ RSpec.describe ApplicationRecord do
.
to
raise_error
(
ActiveRecord
::
RecordNotFound
)
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
describe
'.underscore'
do
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment