Class: WorkItems::DataSync::Handlers::Notes::CopyService
- Inherits:
-
Object
- Object
- WorkItems::DataSync::Handlers::Notes::CopyService
- Defined in:
- app/services/work_items/data_sync/handlers/notes/copy_service.rb
Constant Summary collapse
- BATCH_SIZE =
50
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize(current_user, source_noteable, target_noteable) ⇒ CopyService
constructor
A new instance of CopyService.
Constructor Details
#initialize(current_user, source_noteable, target_noteable) ⇒ CopyService
Returns a new instance of CopyService.
14 15 16 17 18 19 20 21 |
# File 'app/services/work_items/data_sync/handlers/notes/copy_service.rb', line 14 def initialize(current_user, source_noteable, target_noteable) @current_user = current_user @source_noteable = source_noteable @target_noteable = target_noteable @source_parent = source_noteable.resource_parent @target_parent = target_noteable.resource_parent @new_discussion_ids = {} end |
Instance Method Details
#execute ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'app/services/work_items/data_sync/handlers/notes/copy_service.rb', line 23 def execute return ServiceResponse.error(message: 'Noteables must be different') if source_noteable == target_noteable source_noteable.notes_with_associations.each_batch(of: BATCH_SIZE) do |notes_batch| next if notes_batch.empty? Note.transaction do notes_ids_map = allocate_new_ids(notes_batch, :id, 'notes_id_seq') ::Note.insert_all(new_notes(notes_batch, notes_ids_map)) copy_notes_emoji(notes_ids_map) (notes_ids_map) copy_notes_user_mentions(notes_ids_map) end end ServiceResponse.success end |