Class: MergeRequestDiffCommit

Inherits:
ApplicationRecord show all
Includes:
BulkInsertSafe, CachedCommit, ShaAttribute
Defined in:
app/models/merge_request_diff_commit.rb

Constant Summary

Constants included from BulkInsertSafe

BulkInsertSafe::ALLOWED_CALLBACKS, BulkInsertSafe::DEFAULT_BATCH_SIZE, BulkInsertSafe::MethodNotAllowedError, BulkInsertSafe::PrimaryKeySetError

Class Method Summary collapse

Methods included from CachedCommit

#parent_ids, #to_hash

Methods inherited from ApplicationRecord

at_most, id_in, id_not_in, iid_in, pluck_primary_key, primary_key_in, safe_ensure_unique, safe_find_or_create_by, safe_find_or_create_by!, underscore, without_order

Class Method Details

.create_bulk(merge_request_diff_id, commits) ⇒ Object

Deprecated; use `bulk_insert!` from `BulkInsertSafe` mixin instead. cf. gitlab.com/gitlab-org/gitlab/issues/207989 for progress


15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'app/models/merge_request_diff_commit.rb', line 15

def self.create_bulk(merge_request_diff_id, commits)
  rows = commits.map.with_index do |commit, index|
    # See #parent_ids.
    commit_hash = commit.to_hash.except(:parent_ids)
    sha = commit_hash.delete(:id)

    commit_hash.merge(
      merge_request_diff_id: merge_request_diff_id,
      relative_order: index,
      sha: Gitlab::Database::ShaAttribute.serialize(sha), # rubocop:disable Cop/ActiveRecordSerialize
      authored_date: Gitlab::Database.sanitize_timestamp(commit_hash[:authored_date]),
      committed_date: Gitlab::Database.sanitize_timestamp(commit_hash[:committed_date])
    )
  end

  Gitlab::Database.bulk_insert(self.table_name, rows) # rubocop:disable Gitlab/BulkInsert
end