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
0
Merge Requests
0
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
Léo-Paul Géneau
gitlab-ce
Commits
32d96d48
Commit
32d96d48
authored
Jul 23, 2018
by
Gabriel Mazetto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Apply pattern to make `find_or_create` atomic
parent
2d85ad23
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
7 deletions
+10
-7
app/models/site_statistic.rb
app/models/site_statistic.rb
+10
-7
No files found.
app/models/site_statistic.rb
View file @
32d96d48
...
...
@@ -25,18 +25,21 @@ class SiteStatistic < ActiveRecord::Base
return
unless
available?
# we have quite a lot of specs testing migrations, we need this and the rescue to not break them
SiteStatistic
.
transaction
(
requires_new:
true
)
do
SiteStatistic
.
first_or_create
self
.
fetch
# make sure record exists
attribute
=
self
.
connection
.
quote_column_name
(
raw_attribute
)
# will be running on its own transaction context
yield
(
attribute
)
end
end
def
self
.
fetch
SiteStatistic
.
transaction
(
requires_new:
true
)
do
SiteStatistic
.
first_or_create!
end
rescue
ActiveRecord
::
RecordNotUnique
retry
end
def
self
.
available?
@available_flag
||=
ActiveRecord
::
Migrator
.
current_version
>=
REQUIRED_SCHEMA_VERSION
...
...
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