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
a6ae49d3
Commit
a6ae49d3
authored
Jun 18, 2020
by
Matthias Käppler
Committed by
Achilleas Pipinellis
Jun 18, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove blacklist/whitelist language in bulk-insert-safe
parent
488e0370
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
10 additions
and
14 deletions
+10
-14
app/models/concerns/bulk_insert_safe.rb
app/models/concerns/bulk_insert_safe.rb
+2
-6
doc/development/insert_into_tables_in_batches.md
doc/development/insert_into_tables_in_batches.md
+3
-3
spec/support/shared_examples/models/concerns/bulk_insert_safe_shared_examples.rb
...mples/models/concerns/bulk_insert_safe_shared_examples.rb
+5
-5
No files found.
app/models/concerns/bulk_insert_safe.rb
View file @
a6ae49d3
...
...
@@ -37,7 +37,7 @@ module BulkInsertSafe
# These are the callbacks we think safe when used on models that are
# written to the database in bulk
CALLBACK_NAME_WHITELIST
=
Set
[
ALLOWED_CALLBACKS
=
Set
[
:initialize
,
:validate
,
:validation
,
...
...
@@ -179,16 +179,12 @@ module BulkInsertSafe
end
def
_bulk_insert_callback_allowed?
(
name
,
args
)
_bulk_insert_whitelisted
?
(
name
)
||
_bulk_insert_saved_from_belongs_to?
(
name
,
args
)
ALLOWED_CALLBACKS
.
include
?
(
name
)
||
_bulk_insert_saved_from_belongs_to?
(
name
,
args
)
end
# belongs_to associations will install a before_save hook during class loading
def
_bulk_insert_saved_from_belongs_to?
(
name
,
args
)
args
.
first
==
:before
&&
args
.
second
.
to_s
.
start_with?
(
'autosave_associated_records_for_'
)
end
def
_bulk_insert_whitelisted?
(
name
)
CALLBACK_NAME_WHITELIST
.
include?
(
name
)
end
end
end
doc/development/insert_into_tables_in_batches.md
View file @
a6ae49d3
...
...
@@ -121,10 +121,10 @@ These callbacks cannot be used with bulk insertions, since they are meant to be
every instance that is saved or created. Since these events do not fire when
records are inserted in bulk, we currently disallow their use.
The specifics around which callbacks are
dis
allowed are defined in
The specifics around which callbacks are
explicitly
allowed are defined in
[
`BulkInsertSafe`
](
https://gitlab.com/gitlab-org/gitlab/-/blob/master/app/models/concerns/bulk_insert_safe.rb
)
.
Consult the module source code for details. If your class uses
any of the blacklis
ted
functionality, and you
`include BulkInsertSafe`
,
the application will fail with an error.
Consult the module source code for details. If your class uses
callbacks that are not explicitly designa
ted
safe and you
`include BulkInsertSafe`
the application will fail with an error.
### `BulkInsertSafe` versus `InsertAll`
...
...
spec/support/shared_examples/models/concerns/bulk_insert_safe_shared_examples.rb
View file @
a6ae49d3
...
...
@@ -7,17 +7,17 @@ RSpec.shared_examples 'a BulkInsertSafe model' do |klass|
let
(
:target_class
)
{
klass
.
dup
}
# We consider all callbacks unsafe for bulk insertions unless we have explicitly
#
whitelisted them (esp. anything related to :save, :create, :commit
etc.)
let
(
:
callback_method_blacklist
)
do
#
allowed them (especially anything related to :save, :create, :commit,
etc.)
let
(
:
unsafe_callbacks
)
do
ActiveRecord
::
Callbacks
::
CALLBACKS
.
reject
do
|
callback
|
cb_name
=
callback
.
to_s
.
gsub
(
/(before_|after_|around_)/
,
''
).
to_sym
BulkInsertSafe
::
CALLBACK_NAME_WHITELIST
.
include?
(
cb_name
)
BulkInsertSafe
::
ALLOWED_CALLBACKS
.
include?
(
cb_name
)
end
.
to_set
end
context
'when calling class methods directly'
do
it
'raises an error when method is not bulk-insert safe'
do
callback_method_blacklist
.
each
do
|
m
|
unsafe_callbacks
.
each
do
|
m
|
expect
{
target_class
.
send
(
m
,
nil
)
}.
to
(
raise_error
(
BulkInsertSafe
::
MethodNotAllowedError
),
"Expected call to
#{
m
}
to raise an error, but it didn't"
...
...
@@ -26,7 +26,7 @@ RSpec.shared_examples 'a BulkInsertSafe model' do |klass|
end
it
'does not raise an error when method is bulk-insert safe'
do
BulkInsertSafe
::
CALLBACK_NAME_WHITELIST
.
each
do
|
name
|
BulkInsertSafe
::
ALLOWED_CALLBACKS
.
each
do
|
name
|
expect
{
target_class
.
set_callback
(
name
)
{}
}.
not_to
raise_error
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