2018-07-25 05:30:33 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-03-28 09:17:42 -04:00
|
|
|
class MergeRequestDiffCommit < ApplicationRecord
|
2020-02-12 16:08:48 -05:00
|
|
|
include BulkInsertSafe
|
2017-06-16 10:00:58 -04:00
|
|
|
include ShaAttribute
|
2020-01-29 10:08:59 -05:00
|
|
|
include CachedCommit
|
2017-06-16 10:00:58 -04:00
|
|
|
|
|
|
|
belongs_to :merge_request_diff
|
|
|
|
|
|
|
|
sha_attribute :sha
|
|
|
|
alias_attribute :id, :sha
|
|
|
|
|
2020-03-04 07:07:52 -05:00
|
|
|
# Deprecated; use `bulk_insert!` from `BulkInsertSafe` mixin instead.
|
|
|
|
# cf. https://gitlab.com/gitlab-org/gitlab/issues/207989 for progress
|
2017-06-16 10:00:58 -04:00
|
|
|
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,
|
2020-01-29 10:08:59 -05:00
|
|
|
sha: Gitlab::Database::ShaAttribute.serialize(sha), # rubocop:disable Cop/ActiveRecordSerialize
|
2017-10-30 19:21:56 -04:00
|
|
|
authored_date: Gitlab::Database.sanitize_timestamp(commit_hash[:authored_date]),
|
|
|
|
committed_date: Gitlab::Database.sanitize_timestamp(commit_hash[:committed_date])
|
2017-06-16 10:00:58 -04:00
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
Gitlab::Database.bulk_insert(self.table_name, rows)
|
|
|
|
end
|
|
|
|
end
|