2021-06-08 01:23:25 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Ci
|
|
|
|
module JobArtifacts
|
2023-03-17 16:20:25 +05:30
|
|
|
# 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.
|
2021-06-08 01:23:25 +05:30
|
|
|
class DestroyAssociationsService
|
|
|
|
BATCH_SIZE = 100
|
|
|
|
|
|
|
|
def initialize(job_artifacts_relation)
|
|
|
|
@job_artifacts_relation = job_artifacts_relation
|
2023-03-17 16:20:25 +05:30
|
|
|
@statistics_updates = {}
|
2021-06-08 01:23:25 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def destroy_records
|
|
|
|
@job_artifacts_relation.each_batch(of: BATCH_SIZE) do |relation|
|
2023-01-13 00:05:48 +05:30
|
|
|
service = Ci::JobArtifacts::DestroyBatchService.new(relation, pick_up_at: Time.current)
|
2021-06-08 01:23:25 +05:30
|
|
|
result = service.execute(update_stats: false)
|
2023-03-17 16:20:25 +05:30
|
|
|
@statistics_updates.merge!(result[:statistics_updates]) do |_project, existing_updates, new_updates|
|
|
|
|
existing_updates.concat(new_updates)
|
|
|
|
end
|
2021-06-08 01:23:25 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def update_statistics
|
2023-03-17 16:20:25 +05:30
|
|
|
@statistics_updates.each do |project, increments|
|
|
|
|
ProjectStatistics.bulk_increment_statistic(project, Ci::JobArtifact.project_statistics_name, increments)
|
2021-06-08 01:23:25 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|