diff options
Diffstat (limited to 'app/services/events/destroy_service.rb')
-rw-r--r-- | app/services/events/destroy_service.rb | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/app/services/events/destroy_service.rb b/app/services/events/destroy_service.rb index fdb718f0fcb..3a0a7b339bf 100644 --- a/app/services/events/destroy_service.rb +++ b/app/services/events/destroy_service.rb @@ -2,20 +2,29 @@ module Events class DestroyService + BATCH_SIZE = 50 + def initialize(project) @project = project end def execute - project.events.all.delete_all + loop do + count = delete_events_in_batches + break if count < BATCH_SIZE + end ServiceResponse.success(message: 'Events were deleted.') - rescue StandardError - ServiceResponse.error(message: 'Failed to remove events.') + rescue StandardError => e + ServiceResponse.error(message: e.message) end private attr_reader :project + + def delete_events_in_batches + project.events.limit(BATCH_SIZE).delete_all + end end end |