Add active_record.destroy_association_async_batch_size configuration#44617
Merged
jhawthorn merged 1 commit intorails:mainfrom Mar 9, 2022
nholden:destroy-async-batch
Merged
Add active_record.destroy_association_async_batch_size configuration#44617jhawthorn merged 1 commit intorails:mainfrom nholden:destroy-async-batch
active_record.destroy_association_async_batch_size configuration#44617jhawthorn merged 1 commit intorails:mainfrom
nholden:destroy-async-batch
Conversation
jhawthorn
reviewed
Mar 4, 2022
jhawthorn
reviewed
Mar 7, 2022
jhawthorn
approved these changes
Mar 7, 2022
This allows applications to specify the maximum number of records that will be destroyed in a single background job by the `dependent: :destroy_async` association option. By default, the current behavior will remain the same: when a parent record is destroyed, all dependent records will be destroyed in a single background job. If the number of dependent records is greater than this configuration, the records will be destroyed in multiple background jobs. At GitHub, we have a custom method for destroying associated records in the background that we'd like to replace with `dependent: :destroy_async`. Some associations have a large number of dependent records, and our infrastructure requires that background jobs complete quickly, so we limit the maximum number of dependent records destroyed in a single background job and enqueue additional jobs when the number of records exceeds that limit.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This allows applications to specify the maximum number of records that will be destroyed in a single background job by the
dependent: :destroy_asyncassociation option. By default, the current behavior will remain the same: when a parent record is destroyed, all dependent records will be destroyed in a single background job. If the number of dependent records is greater than this configuration, the records will be destroyed in multiple background jobs.At GitHub, we have a custom method for destroying associated records in the background that we'd like to replace with
dependent: :destroy_async. Some associations have a large number of dependent records, and our infrastructure requires that background jobs complete quickly, so we limit the maximum number of dependent records destroyed in a single background job and enqueue additional jobs when the number of records exceeds that limit.