-
Notifications
You must be signed in to change notification settings - Fork 897
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow batch disconnect for the batch strategy #15699
Allow batch disconnect for the batch strategy #15699
Conversation
Allow batch disconnect for the batch strategy
Checked commit Ladas@2cb8567 with ruby 2.2.6, rubocop 0.47.1, and haml-lint 0.20.0 |
|
||
# Is the delete_method rails standard deleting method? | ||
rails_delete = %i(destroy delete).include?(inventory_collection.delete_method) | ||
if !rails_delete && inventory_collection.model_class.respond_to?(inventory_collection.delete_method) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These look like they could be cleaned up a bit, maybe move the logic into the InventoryCollection
but that can be a follow-up PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps InventoryCollection having :batch_delete_method
param, instead of magic implication of having class method with same name?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
inventory_collection.model_class.public_send(inventory_collection.delete_method, records.map(&:id)) | ||
else | ||
# We have either standard :destroy and :delete rails method, or custom instance level delete method | ||
# Note: The standard :destroy and :delete rails method can't be batched because of the hooks and cascade destroy |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My impression is that delete doesn't do any cascading/callback and can be batched without instantiation using model.delete([ids...])
or where(...).delete_all
.
The row is simply removed with an SQL DELETE statement on the record's primary key, and no callbacks are executed.
...
To enforce the object's before_destroy and after_destroy callbacks or any :dependent association options, use #destroy.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm right, I will remove the delete from there entirely, since we do not really use it anyway.
Allow batch disconnect for the batch strategy
Example of ContainerImage batch disconnect strategy is here: #15698