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

destroy_service.rb « gpg_keys « services « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: c8ee90db9f6b988ed94f60742d0629445dc639b0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# frozen_string_literal: true

module GpgKeys
  class DestroyService < Keys::BaseService
    BATCH_SIZE = 1000

    def execute(key)
      nullify_signatures(key)
      key.destroy
    end

    private

    # When a GPG key is deleted, the related signatures have their gpg_key_id column nullified
    # However, when the number of signatures is large, then a timeout may happen
    # The signatures are processed in batches before GPG key delete is attempted in order to
    # avoid timeouts
    def nullify_signatures(key)
      key.gpg_signatures.each_batch(of: BATCH_SIZE) do |batch|
        batch.update_all(gpg_key_id: nil)
      end
    end
  end
end

GpgKeys::DestroyService.prepend_mod