debian-mirror-gitlab/app/services/suggestions/create_service.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

35 lines
1.1 KiB
Ruby
Raw Normal View History

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-12-11 22:18:48 +05:30
ApplicationRecord.legacy_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
2021-11-11 11:23:49 +05:30
Gitlab::UsageDataCounters::MergeRequestActivityUniqueCounter.track_add_suggestion_action(note: @note)
2019-02-15 15:39:39 +05:30
end
end
end