-
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -99,11 +99,21 @@ def save!(inventory_collection, association) | |
end | ||
|
||
def destroy_records(records) | ||
# TODO(lsmola) we need at least batch disconnect. Batch destroy won't be probably possible because of the | ||
# :dependent => :destroy. | ||
ActiveRecord::Base.transaction do | ||
records.each do |record| | ||
delete_record!(inventory_collection, record) | ||
return false unless inventory_collection.delete_allowed? | ||
return if records.blank? | ||
|
||
# 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) | ||
# We have custom delete method defined on a class, that means it supports batch destroy | ||
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 commentThe 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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
ActiveRecord::Base.transaction do | ||
records.each do |record| | ||
delete_record!(inventory_collection, record) | ||
end | ||
end | ||
end | ||
end | ||
|
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 PRThere 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?