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
fd9377fa
Commit
fd9377fa
authored
Aug 04, 2018
by
Gabriel Mazetto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added method to re-populating SiteStatitiscs counter
parent
76cd1dd6
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
1 deletion
+27
-1
app/models/site_statistic.rb
app/models/site_statistic.rb
+15
-1
spec/models/site_statistic_spec.rb
spec/models/site_statistic_spec.rb
+12
-0
No files found.
app/models/site_statistic.rb
View file @
fd9377fa
...
...
@@ -49,7 +49,7 @@ class SiteStatistic < ActiveRecord::Base
#
# @return [SiteStatistic] record with tracked information
def
self
.
fetch
SiteStatistic
.
transaction
(
requires_new:
true
)
do
transaction
(
requires_new:
true
)
do
SiteStatistic
.
first_or_create!
end
rescue
ActiveRecord
::
RecordNotUnique
...
...
@@ -73,4 +73,18 @@ class SiteStatistic < ActiveRecord::Base
super
end
def
self
.
recalculate_counters!
transaction
do
# see https://gitlab.com/gitlab-org/gitlab-ce/issues/48967
ActiveRecord
::
Base
.
connection
.
execute
(
'SET LOCAL statement_timeout TO 0'
)
if
Gitlab
::
Database
.
postgresql?
self
.
update_all
(
'repositories_count = (SELECT COUNT(*) FROM projects)'
)
end
transaction
do
# see https://gitlab.com/gitlab-org/gitlab-ce/issues/48967
ActiveRecord
::
Base
.
connection
.
execute
(
'SET LOCAL statement_timeout TO 0'
)
if
Gitlab
::
Database
.
postgresql?
self
.
update_all
(
'wikis_count = (SELECT COUNT(*) FROM project_features WHERE wiki_access_level != 0)'
)
end
end
end
spec/models/site_statistic_spec.rb
View file @
fd9377fa
...
...
@@ -80,4 +80,16 @@ describe SiteStatistic do
end
end
end
describe
'.recalculate_counters!'
do
it
'recalculates existing counters'
do
create
(
:project
)
described_class
.
fetch
.
update
(
repositories_count:
0
,
wikis_count:
0
)
described_class
.
recalculate_counters!
expect
(
described_class
.
fetch
.
repositories_count
).
to
eq
(
1
)
expect
(
described_class
.
fetch
.
wikis_count
).
to
eq
(
1
)
end
end
end
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