2019-02-15 15:39:39 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Suggestions
|
|
|
|
class CreateService
|
|
|
|
def initialize(note)
|
|
|
|
@note = note
|
|
|
|
end
|
|
|
|
|
|
|
|
def execute
|
|
|
|
return unless @note.supports_suggestion?
|
|
|
|
|
2019-07-07 11:18:12 +05:30
|
|
|
suggestions = Gitlab::Diff::SuggestionsParser.parse(@note.note,
|
|
|
|
project: @note.project,
|
|
|
|
position: @note.position)
|
2019-02-15 15:39:39 +05:30
|
|
|
|
|
|
|
rows =
|
|
|
|
suggestions.map.with_index do |suggestion, index|
|
2019-07-07 11:18:12 +05:30
|
|
|
creation_params =
|
|
|
|
suggestion.to_hash.slice(:from_content,
|
|
|
|
:to_content,
|
|
|
|
:lines_above,
|
|
|
|
:lines_below)
|
2019-02-15 15:39:39 +05:30
|
|
|
|
2019-07-07 11:18:12 +05:30
|
|
|
creation_params.merge!(note_id: @note.id, relative_order: index)
|
2019-02-15 15:39:39 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
rows.in_groups_of(100, false) do |rows|
|
2021-10-27 15:23:28 +05:30
|
|
|
Gitlab::Database.main.bulk_insert('suggestions', rows) # rubocop:disable Gitlab/BulkInsert
|
2019-02-15 15:39:39 +05:30
|
|
|
end
|
2021-03-11 19:13:27 +05:30
|
|
|
|
|
|
|
Gitlab::UsageDataCounters::MergeRequestActivityUniqueCounter.track_add_suggestion_action(user: @note.author)
|
2019-02-15 15:39:39 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|