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
1a54986c
Commit
1a54986c
authored
Aug 15, 2018
by
Gabriel Mazetto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor SiteStatistics to extract refresh logic into a rake task
parent
696a5fce
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
47 additions
and
26 deletions
+47
-26
app/models/site_statistic.rb
app/models/site_statistic.rb
+0
-14
lib/tasks/gitlab/site_statistics.rake
lib/tasks/gitlab/site_statistics.rake
+23
-0
spec/models/site_statistic_spec.rb
spec/models/site_statistic_spec.rb
+0
-12
spec/tasks/gitlab/site_statistics_rake_spec.rb
spec/tasks/gitlab/site_statistics_rake_spec.rb
+24
-0
No files found.
app/models/site_statistic.rb
View file @
1a54986c
...
...
@@ -73,18 +73,4 @@ 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
lib/tasks/gitlab/site_statistics.rake
0 → 100644
View file @
1a54986c
namespace
:gitlab
do
desc
"GitLab | Refresh Site Statistics counters"
task
refresh_site_statistics: :environment
do
puts
'Updating Site Statistics counters: '
print
'* Repositories... '
SiteStatistic
.
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?
SiteStatistic
.
update_all
(
'repositories_count = (SELECT COUNT(*) FROM projects)'
)
end
puts
'OK!'
.
color
(
:green
)
print
'* Wikis... '
SiteStatistic
.
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?
SiteStatistic
.
update_all
(
'wikis_count = (SELECT COUNT(*) FROM project_features WHERE wiki_access_level != 0)'
)
end
puts
'OK!'
.
color
(
:green
)
puts
end
end
spec/models/site_statistic_spec.rb
View file @
1a54986c
...
...
@@ -80,16 +80,4 @@ 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
spec/tasks/gitlab/site_statistics_rake_spec.rb
0 → 100644
View file @
1a54986c
# frozen_string_literal: true
require
'rake_helper'
describe
'rake gitlab:refresh_site_statistics'
do
before
do
Rake
.
application
.
rake_require
'tasks/gitlab/site_statistics'
create
(
:project
)
SiteStatistic
.
fetch
.
update
(
repositories_count:
0
,
wikis_count:
0
)
end
let
(
:task
)
{
'gitlab:refresh_site_statistics'
}
it
'recalculates existing counters'
do
run_rake_task
(
task
)
expect
(
SiteStatistic
.
fetch
.
repositories_count
).
to
eq
(
1
)
expect
(
SiteStatistic
.
fetch
.
wikis_count
).
to
eq
(
1
)
end
it
'displays message listing counters'
do
expect
{
run_rake_task
(
task
)
}.
to
output
(
/Updating Site Statistics counters:.* Repositories\.\.\. OK!.* Wikis\.\.\. OK!/m
).
to_stdout
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