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

destroy_associations_service.rb « job_artifacts « ci « services « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 08d7f7f6f0209745943d8af772b6c173171be49f (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
# frozen_string_literal: true

module Ci
  module JobArtifacts
    class DestroyAssociationsService
      BATCH_SIZE = 100

      def initialize(job_artifacts_relation)
        @job_artifacts_relation = job_artifacts_relation
        @statistics = {}
      end

      def destroy_records
        @job_artifacts_relation.each_batch(of: BATCH_SIZE) do |relation|
          service = Ci::JobArtifacts::DestroyBatchService.new(relation, pick_up_at: Time.current, fix_expire_at: false)
          result  = service.execute(update_stats: false)
          updates = result[:statistics_updates]

          @statistics.merge!(updates) { |_key, oldval, newval| newval + oldval }
        end
      end

      def update_statistics
        @statistics.each do |project, delta|
          project.increment_statistic_value(Ci::JobArtifact.project_statistics_name, delta)
        end
      end
    end
  end
end