Module: BulkInsertSafe
- Extended by:
- ActiveSupport::Concern
- Included in:
- AuditEvent, BatchedGitRefUpdates::Deletion, Ci::BuildNeed, Ci::BuildTag, Ci::Catalog::Resources::Component, Ci::JobAnnotation, Ci::JobVariable, Ci::RunnerTagging, DraftNote, Gitlab::Database::BackgroundMigrationJob, Import::SourceUserPlaceholderReference, IssueEmailParticipant, LabelLink, MergeRequestDiffCommit, MergeRequestDiffFile, MergeRequestReviewer, MergeRequestsClosingIssues, Projects::BuildArtifactsSizeRefresh
- Defined in:
- app/models/concerns/bulk_insert_safe.rb
Overview
A mixin for ActiveRecord models that enables callers to insert instances of the target class into the database en-bloc via the [bulk_insert] method.
Upon inclusion in the target class, the mixin will perform a number of checks to ensure that the target is eligible for bulk insertions. For instance, it must not use ActiveRecord callbacks that fire between [save]s, since these would not run properly when instances are inserted in bulk.
The mixin uses ActiveRecord 6’s [InsertAll] type internally for bulk insertions. Unlike [InsertAll], however, it requires you to pass instances of the target type rather than row hashes, since it will run validations prior to insertion.
Constant Summary collapse
- ALLOWED_CALLBACKS =
These are the callbacks we think safe when used on models that are written to the database in bulk
Set[ :initialize, :validate, :validation, :find, :destroy ].freeze
- DEFAULT_BATCH_SIZE =
500
- MethodNotAllowedError =
Class.new(StandardError)
- PrimaryKeySetError =
Class.new(StandardError)