gitlab-org--gitlab-foss/app/services/notes/update_service.rb
Kamil Trzciński 650f40865e Forbid the use of #reload and prefer #reset
The `#reload` makes to load all objects into memory,
and the main purpose of `#reload` is to drop the association cache.

The `#reset` seems to solve exactly that case.
2019-04-15 13:05:14 +02:00

31 lines
789 B
Ruby

# frozen_string_literal: true
module Notes
class UpdateService < BaseService
def execute(note)
return note unless note.editable?
old_mentioned_users = note.mentioned_users.to_a
note.update(params.merge(updated_by: current_user))
note.create_new_cross_references!(current_user)
if note.previous_changes.include?('note')
TodoService.new.update_note(note, current_user, old_mentioned_users)
end
if note.supports_suggestion?
Suggestion.transaction do
note.suggestions.delete_all
Suggestions::CreateService.new(note).execute
end
# We need to refresh the previous suggestions call cache
# in order to get the new records.
note.reset
end
note
end
end
end