Class: Issuable::DestroyLabelLinksService

Inherits:
Object
  • Object
show all
Defined in:
app/services/issuable/destroy_label_links_service.rb

Constant Summary collapse

BATCH_SIZE =
100

Instance Method Summary collapse

Constructor Details

#initialize(target_id, target_type) ⇒ DestroyLabelLinksService

Returns a new instance of DestroyLabelLinksService.


7
8
9
10
# File 'app/services/issuable/destroy_label_links_service.rb', line 7

def initialize(target_id, target_type)
  @target_id = target_id
  @target_type = target_type
end

Instance Method Details

#executeObject


12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/services/issuable/destroy_label_links_service.rb', line 12

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
    result = LabelLink.connection.execute(delete_query)

    break if result.cmd_tuples == 0
  end
end