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
35eecbf2
Commit
35eecbf2
authored
Aug 17, 2018
by
Gabriel Mazetto
Committed by
Yorick Peterse
Aug 17, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[EE] Fix SiteStatistics wikis_count
parent
491aba1e
Changes
10
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
116 additions
and
15 deletions
+116
-15
app/models/site_statistic.rb
app/models/site_statistic.rb
+1
-1
changelogs/unreleased/repopulate_site_statistics.yml
changelogs/unreleased/repopulate_site_statistics.yml
+5
-0
db/post_migrate/20180809195358_migrate_null_wiki_access_levels.rb
...migrate/20180809195358_migrate_null_wiki_access_levels.rb
+32
-0
db/schema.rb
db/schema.rb
+1
-1
lib/tasks/gitlab/site_statistics.rake
lib/tasks/gitlab/site_statistics.rake
+23
-0
spec/lib/gitlab/bare_repository_import/importer_spec.rb
spec/lib/gitlab/bare_repository_import/importer_spec.rb
+0
-4
spec/lib/system_check/simple_executor_spec.rb
spec/lib/system_check/simple_executor_spec.rb
+0
-9
spec/migrations/migrate_null_wiki_access_levels_spec.rb
spec/migrations/migrate_null_wiki_access_levels_spec.rb
+29
-0
spec/spec_helper.rb
spec/spec_helper.rb
+1
-0
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 @
35eecbf2
...
@@ -49,7 +49,7 @@ class SiteStatistic < ActiveRecord::Base
...
@@ -49,7 +49,7 @@ class SiteStatistic < ActiveRecord::Base
#
#
# @return [SiteStatistic] record with tracked information
# @return [SiteStatistic] record with tracked information
def
self
.
fetch
def
self
.
fetch
SiteStatistic
.
transaction
(
requires_new:
true
)
do
transaction
(
requires_new:
true
)
do
SiteStatistic
.
first_or_create!
SiteStatistic
.
first_or_create!
end
end
rescue
ActiveRecord
::
RecordNotUnique
rescue
ActiveRecord
::
RecordNotUnique
...
...
changelogs/unreleased/repopulate_site_statistics.yml
0 → 100644
View file @
35eecbf2
---
title
:
Migrate NULL wiki_access_level to correct number so we count active wikis correctly
merge_request
:
21030
author
:
type
:
changed
db/post_migrate/20180809195358_migrate_null_wiki_access_levels.rb
0 → 100644
View file @
35eecbf2
# frozen_string_literal: true
class
MigrateNullWikiAccessLevels
<
ActiveRecord
::
Migration
include
Gitlab
::
Database
::
MigrationHelpers
DOWNTIME
=
false
disable_ddl_transaction!
class
ProjectFeature
<
ActiveRecord
::
Base
include
EachBatch
self
.
table_name
=
'project_features'
end
def
up
ProjectFeature
.
where
(
wiki_access_level:
nil
).
each_batch
do
|
relation
|
relation
.
update_all
(
wiki_access_level:
20
)
end
# We need to re-count wikis as previous attempt was not considering the NULLs.
transaction
do
execute
(
'SET LOCAL statement_timeout TO 0'
)
if
Gitlab
::
Database
.
postgresql?
# see https://gitlab.com/gitlab-org/gitlab-ce/issues/48967
execute
(
"UPDATE site_statistics SET wikis_count = (SELECT COUNT(*) FROM project_features WHERE wiki_access_level != 0)"
)
end
end
def
down
# there is no way to rollback this change, there are no downsides in keeping migrated data.
end
end
db/schema.rb
View file @
35eecbf2
...
@@ -11,7 +11,7 @@
...
@@ -11,7 +11,7 @@
#
#
# It's strongly recommended that you check this file into your version control system.
# It's strongly recommended that you check this file into your version control system.
ActiveRecord
::
Schema
.
define
(
version:
2018080
8162000
)
do
ActiveRecord
::
Schema
.
define
(
version:
2018080
9195358
)
do
# These are extensions that must be enabled in order to support this database
# These are extensions that must be enabled in order to support this database
enable_extension
"plpgsql"
enable_extension
"plpgsql"
...
...
lib/tasks/gitlab/site_statistics.rake
0 → 100644
View file @
35eecbf2
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/lib/gitlab/bare_repository_import/importer_spec.rb
View file @
35eecbf2
...
@@ -10,9 +10,6 @@ describe Gitlab::BareRepositoryImport::Importer, :seed_helper do
...
@@ -10,9 +10,6 @@ describe Gitlab::BareRepositoryImport::Importer, :seed_helper do
subject
(
:importer
)
{
described_class
.
new
(
admin
,
bare_repository
)
}
subject
(
:importer
)
{
described_class
.
new
(
admin
,
bare_repository
)
}
before
do
before
do
@rainbow
=
Rainbow
.
enabled
Rainbow
.
enabled
=
false
allow
(
described_class
).
to
receive
(
:log
)
allow
(
described_class
).
to
receive
(
:log
)
end
end
...
@@ -20,7 +17,6 @@ describe Gitlab::BareRepositoryImport::Importer, :seed_helper do
...
@@ -20,7 +17,6 @@ describe Gitlab::BareRepositoryImport::Importer, :seed_helper do
FileUtils
.
rm_rf
(
base_dir
)
FileUtils
.
rm_rf
(
base_dir
)
TestEnv
.
clean_test_path
TestEnv
.
clean_test_path
ensure_seeds
ensure_seeds
Rainbow
.
enabled
=
@rainbow
end
end
shared_examples
'importing a repository'
do
shared_examples
'importing a repository'
do
...
...
spec/lib/system_check/simple_executor_spec.rb
View file @
35eecbf2
...
@@ -98,15 +98,6 @@ describe SystemCheck::SimpleExecutor do
...
@@ -98,15 +98,6 @@ describe SystemCheck::SimpleExecutor do
end
end
end
end
before
do
@rainbow
=
Rainbow
.
enabled
Rainbow
.
enabled
=
false
end
after
do
Rainbow
.
enabled
=
@rainbow
end
describe
'#component'
do
describe
'#component'
do
it
'returns stored component name'
do
it
'returns stored component name'
do
expect
(
subject
.
component
).
to
eq
(
'Test'
)
expect
(
subject
.
component
).
to
eq
(
'Test'
)
...
...
spec/migrations/migrate_null_wiki_access_levels_spec.rb
0 → 100644
View file @
35eecbf2
# frozen_string_literal: true
require
'spec_helper'
require
Rails
.
root
.
join
(
'db'
,
'post_migrate'
,
'20180809195358_migrate_null_wiki_access_levels.rb'
)
describe
MigrateNullWikiAccessLevels
,
:migration
do
let
(
:namespaces
)
{
table
(
'namespaces'
)
}
let
(
:projects
)
{
table
(
:projects
)
}
let
(
:project_features
)
{
table
(
:project_features
)
}
let
(
:migration
)
{
described_class
.
new
}
before
do
namespace
=
namespaces
.
create
(
name:
'foo'
,
path:
'foo'
)
projects
.
create!
(
id:
1
,
name:
'gitlab1'
,
path:
'gitlab1'
,
namespace_id:
namespace
.
id
)
projects
.
create!
(
id:
2
,
name:
'gitlab2'
,
path:
'gitlab2'
,
namespace_id:
namespace
.
id
)
projects
.
create!
(
id:
3
,
name:
'gitlab3'
,
path:
'gitlab3'
,
namespace_id:
namespace
.
id
)
project_features
.
create!
(
id:
1
,
project_id:
1
,
wiki_access_level:
nil
)
project_features
.
create!
(
id:
2
,
project_id:
2
,
wiki_access_level:
10
)
project_features
.
create!
(
id:
3
,
project_id:
3
,
wiki_access_level:
20
)
end
describe
'#up'
do
it
'migrates existing project_features with wiki_access_level NULL to 20'
do
expect
{
migration
.
up
}.
to
change
{
project_features
.
where
(
wiki_access_level:
20
).
count
}.
by
(
1
)
end
end
end
spec/spec_helper.rb
View file @
35eecbf2
...
@@ -29,6 +29,7 @@ end
...
@@ -29,6 +29,7 @@ end
# require rainbow gem String monkeypatch, so we can test SystemChecks
# require rainbow gem String monkeypatch, so we can test SystemChecks
require
'rainbow/ext/string'
require
'rainbow/ext/string'
Rainbow
.
enabled
=
false
require_relative
'../ee/spec/spec_helper'
require_relative
'../ee/spec/spec_helper'
...
...
spec/tasks/gitlab/site_statistics_rake_spec.rb
0 → 100644
View file @
35eecbf2
# 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