Class: Ci::JobArtifacts::DestroyAssociationsService

Inherits:
Object
  • Object
show all
Defined in:
app/services/ci/job_artifacts/destroy_associations_service.rb

Overview

This class is used by Ci::JobArtifact’s FastDestroyAll implementation. Ci::JobArtifact.begin_fast_destroy instantiates this service and calls #destroy_records. This will set @statistics_updates instance variables. The same instance is passed to Ci::JobArtifact.finalize_fast_destroy, which then calls #update_statistics, using @statistics_updates set by #destroy_records.

Constant Summary collapse

BATCH_SIZE =
100

Instance Method Summary collapse

Constructor Details

#initialize(job_artifacts_relation) ⇒ DestroyAssociationsService

Returns a new instance of DestroyAssociationsService.



13
14
15
16
# File 'app/services/ci/job_artifacts/destroy_associations_service.rb', line 13

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

Instance Method Details

#destroy_recordsObject



18
19
20
21
22
23
24
25
26
# File 'app/services/ci/job_artifacts/destroy_associations_service.rb', line 18

def destroy_records
  @job_artifacts_relation.each_batch(of: BATCH_SIZE) do |relation|
    service = Ci::JobArtifacts::DestroyBatchService.new(relation, pick_up_at: Time.current)
    result  = service.execute(update_stats: false)
    @statistics_updates.merge!(result[:statistics_updates]) do |_project, existing_updates, new_updates|
      existing_updates.concat(new_updates)
    end
  end
end

#update_statisticsObject



28
29
30
31
32
# File 'app/services/ci/job_artifacts/destroy_associations_service.rb', line 28

def update_statistics
  @statistics_updates.each do |project, increments|
    ProjectStatistics.bulk_increment_statistic(project, Ci::JobArtifact.project_statistics_name, increments)
  end
end