debian-mirror-gitlab/app/services/issuable/destroy_label_links_service.rb

36 lines
692 B
Ruby
Raw Normal View History

2021-06-08 01:23:25 +05:30
# frozen_string_literal: true
module Issuable
class DestroyLabelLinksService
BATCH_SIZE = 100
def initialize(target_id, target_type)
@target_id = target_id
@target_type = target_type
end
def execute
inner_query =
LabelLink
.select(:id)
.for_target(target_id, target_type)
.limit(BATCH_SIZE)
delete_query = <<~SQL
DELETE FROM "#{LabelLink.table_name}"
WHERE id IN (#{inner_query.to_sql})
SQL
loop do
2021-10-27 15:23:28 +05:30
result = LabelLink.connection.execute(delete_query)
2021-06-08 01:23:25 +05:30
break if result.cmd_tuples == 0
end
end
private
attr_reader :target_id, :target_type
end
end