Welcome to mirror list, hosted at ThFree Co, Russian Federation.

batch_destroy_dependent_associations_helper.rb « helpers « support « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 22170de053b4a3e2a001493d69b5fa998d33df5b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
# frozen_string_literal: true

module BatchDestroyDependentAssociationsHelper
  private

  def delete_in_batches_regexps(table, column, resource, items, batch_size: 1000)
    # rubocop:disable Layout/LineLength
    select_query = %r{^SELECT "#{table}".* FROM "#{table}" WHERE.* "#{table}"."#{column}" = #{resource.id}.*ORDER BY "#{table}"."id" ASC LIMIT #{batch_size}}
    # rubocop:enable Layout/LineLength

    [select_query] + items.map { |item| %r{^DELETE FROM "#{table}" WHERE "#{table}"."id" = #{item.id}} }
  end
end