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
Boxiang Sun
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
Hide 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,17 +25,20 @@ class SiteStatistic < ActiveRecord::Base
...
@@ -25,17 +25,20 @@ class SiteStatistic < ActiveRecord::Base
return
unless
available?
return
unless
available?
# we have quite a lot of specs testing migrations, we need this and the rescue to not break them
self
.
fetch
# make sure record exists
SiteStatistic
.
transaction
(
requires_new:
true
)
do
SiteStatistic
.
first_or_create
attribute
=
self
.
connection
.
quote_column_name
(
raw_attribute
)
yield
(
attribute
)
attribute
=
self
.
connection
.
quote_column_name
(
raw_attribute
)
end
# will be running on its own transaction context
yield
(
attribute
)
end
end
def
self
.
fetch
def
self
.
fetch
SiteStatistic
.
first_or_create!
SiteStatistic
.
transaction
(
requires_new:
true
)
do
SiteStatistic
.
first_or_create!
end
rescue
ActiveRecord
::
RecordNotUnique
retry
end
end
def
self
.
available?
def
self
.
available?
...
...
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