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
e9af31bb
Commit
e9af31bb
authored
Feb 15, 2022
by
Matt Kasa
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix use of ActiveRecord::Base in Seeder
Relates to
https://gitlab.com/gitlab-org/gitlab/-/issues/350651
parent
50cec3d8
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
47 additions
and
10 deletions
+47
-10
lib/gitlab/seeder.rb
lib/gitlab/seeder.rb
+27
-10
spec/lib/gitlab/seeder_spec.rb
spec/lib/gitlab/seeder_spec.rb
+20
-0
No files found.
lib/gitlab/seeder.rb
View file @
e9af31bb
...
...
@@ -62,10 +62,6 @@ module Gitlab
end
def
self
.
quiet
# Disable database insertion logs so speed isn't limited by ability to print to console
old_logger
=
ActiveRecord
::
Base
.
logger
ActiveRecord
::
Base
.
logger
=
nil
# Additional seed logic for models.
Project
.
include
(
ProjectSeed
)
User
.
include
(
UserSeed
)
...
...
@@ -75,9 +71,11 @@ module Gitlab
SeedFu
.
quiet
=
true
without_statement_timeout
do
without_new_note_notifications
do
yield
without_database_logging
do
without_statement_timeout
do
without_new_note_notifications
do
yield
end
end
end
...
...
@@ -85,7 +83,6 @@ module Gitlab
ensure
SeedFu
.
quiet
=
false
ActionMailer
::
Base
.
perform_deliveries
=
old_perform_deliveries
ActiveRecord
::
Base
.
logger
=
old_logger
end
def
self
.
without_gitaly_timeout
...
...
@@ -112,10 +109,30 @@ module Gitlab
end
def
self
.
without_statement_timeout
ActiveRecord
::
Base
.
connection
.
execute
(
'SET statement_timeout=0'
)
Gitlab
::
Database
::
EachDatabase
.
each_database_connection
do
|
connection
|
connection
.
execute
(
'SET statement_timeout=0'
)
end
yield
ensure
Gitlab
::
Database
::
EachDatabase
.
each_database_connection
do
|
connection
|
connection
.
execute
(
'RESET statement_timeout'
)
end
end
def
self
.
without_database_logging
old_loggers
=
Gitlab
::
Database
.
database_base_models
.
transform_values
do
|
model
|
model
.
logger
end
Gitlab
::
Database
.
database_base_models
.
each
do
|
_
,
model
|
model
.
logger
=
nil
end
yield
ensure
ActiveRecord
::
Base
.
connection
.
execute
(
'RESET statement_timeout'
)
Gitlab
::
Database
.
database_base_models
.
each
do
|
connection_name
,
model
|
model
.
logger
=
old_loggers
[
connection_name
]
end
end
end
end
...
...
spec/lib/gitlab/seeder_spec.rb
View file @
e9af31bb
...
...
@@ -4,6 +4,26 @@ require 'spec_helper'
RSpec
.
describe
Gitlab
::
Seeder
do
describe
'.quiet'
do
let
(
:database_base_models
)
do
{
main:
ApplicationRecord
,
ci:
Ci
::
ApplicationRecord
}
end
it
'disables database logging'
do
allow
(
Gitlab
::
Database
).
to
receive
(
:database_base_models
)
.
and_return
(
database_base_models
.
with_indifferent_access
)
described_class
.
quiet
do
expect
(
ApplicationRecord
.
logger
).
to
be_nil
expect
(
Ci
::
ApplicationRecord
.
logger
).
to
be_nil
end
expect
(
ApplicationRecord
.
logger
).
not_to
be_nil
expect
(
Ci
::
ApplicationRecord
.
logger
).
not_to
be_nil
end
it
'disables mail deliveries'
do
expect
(
ActionMailer
::
Base
.
perform_deliveries
).
to
eq
(
true
)
...
...
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