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

project_cleanup_service.rb « batched_git_ref_updates « services « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 7367c8be1d1261ec2833ded215a44fa80d3c323d (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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# frozen_string_literal: true

module BatchedGitRefUpdates
  class ProjectCleanupService
    include ::Gitlab::ExclusiveLeaseHelpers

    LOCK_TIMEOUT = 10.minutes
    GITALY_BATCH_SIZE = 100
    QUERY_BATCH_SIZE = 1000
    MAX_DELETES = 10_000

    def initialize(project_id)
      @project_id = project_id
    end

    def execute
      total_deletes = 0

      in_lock("#{self.class}/#{@project_id}", retries: 0, ttl: LOCK_TIMEOUT) do
        project = Project.find_by_id(@project_id)
        break unless project

        Deletion
          .status_pending
          .for_project(@project_id)
          .select_ref_and_identity
          .each_batch(of: QUERY_BATCH_SIZE) do |batch|
          refs = batch.map(&:ref)

          refs.each_slice(GITALY_BATCH_SIZE) do |refs_to_delete|
            project.repository.delete_refs(*refs_to_delete.uniq)
          end

          total_deletes += refs.count
          Deletion.mark_records_processed(batch)

          break if total_deletes >= MAX_DELETES
        end
      end

      { total_deletes: total_deletes }
    end
  end
end