BigW Consortium Gitlab

Commit 2045a771 by Kamil Trzcinski

Rename `job_archive|metadata` to `artifacts_archive|metadata`

parent 2a620e74
...@@ -16,8 +16,8 @@ module Ci ...@@ -16,8 +16,8 @@ module Ci
has_many :trace_sections, class_name: 'Ci::BuildTraceSection' has_many :trace_sections, class_name: 'Ci::BuildTraceSection'
has_many :job_artifacts, class_name: 'Ci::JobArtifact', foreign_key: :job_id, dependent: :destroy # rubocop:disable Cop/ActiveRecordDependent has_many :job_artifacts, class_name: 'Ci::JobArtifact', foreign_key: :job_id, dependent: :destroy # rubocop:disable Cop/ActiveRecordDependent
has_one :job_archive, -> () { where(file_type: Ci::JobArtifact.file_types[:archive]) }, class_name: 'Ci::JobArtifact', foreign_key: :job_id has_one :artifacts_archive, -> () { where(file_type: Ci::JobArtifact.file_types[:archive]) }, class_name: 'Ci::JobArtifact', foreign_key: :job_id
has_one :job_metadata, -> () { where(file_type: Ci::JobArtifact.file_types[:metadata]) }, class_name: 'Ci::JobArtifact', foreign_key: :job_id has_one :artifacts_metadata, -> () { where(file_type: Ci::JobArtifact.file_types[:metadata]) }, class_name: 'Ci::JobArtifact', foreign_key: :job_id
# The "environment" field for builds is a String, and is the unexpanded name # The "environment" field for builds is a String, and is the unexpanded name
def persisted_environment def persisted_environment
......
...@@ -3,11 +3,11 @@ ...@@ -3,11 +3,11 @@
# Meant to be prepended so the interface can stay the same # Meant to be prepended so the interface can stay the same
module ArtifactMigratable module ArtifactMigratable
def artifacts_file def artifacts_file
job_archive&.file || legacy_artifacts_file artifacts_archive&.file || legacy_artifacts_file
end end
def artifacts_metadata def artifacts_metadata
job_metadata&.file || legacy_artifacts_metadata artifacts_metadata&.file || legacy_artifacts_metadata
end end
def artifacts? def artifacts?
...@@ -19,20 +19,20 @@ module ArtifactMigratable ...@@ -19,20 +19,20 @@ module ArtifactMigratable
end end
def artifacts_file_changed? def artifacts_file_changed?
job_archive&.file_changed? || attribute_changed?(:artifacts_file) artifacts_archive&.file_changed? || attribute_changed?(:artifacts_file)
end end
def remove_artifacts_file! def remove_artifacts_file!
if job_archive if artifacts_archive
job_archive.destroy artifacts_archive.destroy
else else
remove_legacy_artifacts_file! remove_legacy_artifacts_file!
end end
end end
def remove_artifacts_metadata! def remove_artifacts_metadata!
if job_metadata if artifacts_metadata
job_metadata.destroy artifacts_metadata.destroy
else else
remove_legacy_artifacts_metadata! remove_legacy_artifacts_metadata!
end end
...@@ -40,6 +40,6 @@ module ArtifactMigratable ...@@ -40,6 +40,6 @@ module ArtifactMigratable
def artifacts_size def artifacts_size
read_attribute(:artifacts_size).to_i + read_attribute(:artifacts_size).to_i +
job_archive&.size.to_i + job_metadata&.size.to_i artifacts_archive&.size.to_i + artifacts_metadata&.size.to_i
end end
end end
...@@ -35,6 +35,9 @@ class ProjectStatistics < ActiveRecord::Base ...@@ -35,6 +35,9 @@ class ProjectStatistics < ActiveRecord::Base
end end
def update_build_artifacts_size def update_build_artifacts_size
# REMARK:
# We perform dual calculation as we run SQL query: sum does not instantiate AR model.
# The Ci::Build#artifacts_size returns sum of ci_builds.artifacts_size and ci_job_artifacts.file_size
self.build_artifacts_size = self.build_artifacts_size =
project.builds.sum(:artifacts_size) + project.builds.sum(:artifacts_size) +
Ci::JobArtifact.artifacts_size_for(self) Ci::JobArtifact.artifacts_size_for(self)
......
...@@ -17,7 +17,7 @@ describe Ci::RetryBuildService do ...@@ -17,7 +17,7 @@ describe Ci::RetryBuildService do
%i[id status user token coverage trace runner artifacts_expire_at %i[id status user token coverage trace runner artifacts_expire_at
artifacts_file artifacts_metadata artifacts_size created_at artifacts_file artifacts_metadata artifacts_size created_at
updated_at started_at finished_at queued_at erased_by updated_at started_at finished_at queued_at erased_by
erased_at auto_canceled_by job_artifacts job_archive job_metadata].freeze erased_at auto_canceled_by job_artifacts artifacts_archive artifacts_metadata].freeze
IGNORE_ACCESSORS = IGNORE_ACCESSORS =
%i[type lock_version target_url base_tags trace_sections %i[type lock_version target_url base_tags trace_sections
......
...@@ -23,7 +23,7 @@ describe ExpireBuildInstanceArtifactsWorker do ...@@ -23,7 +23,7 @@ describe ExpireBuildInstanceArtifactsWorker do
end end
it 'does remove the job artifact record' do it 'does remove the job artifact record' do
expect(build.reload.job_archive).to be_nil expect(build.reload.artifacts_archive).to be_nil
end end
end end
end end
...@@ -42,7 +42,7 @@ describe ExpireBuildInstanceArtifactsWorker do ...@@ -42,7 +42,7 @@ describe ExpireBuildInstanceArtifactsWorker do
end end
it 'does not remove the job artifact record' do it 'does not remove the job artifact record' do
expect(build.reload.job_archive).not_to be_nil expect(build.reload.artifacts_archive).not_to be_nil
end end
end end
...@@ -58,7 +58,7 @@ describe ExpireBuildInstanceArtifactsWorker do ...@@ -58,7 +58,7 @@ describe ExpireBuildInstanceArtifactsWorker do
end end
it 'does not remove the job artifact record' do it 'does not remove the job artifact record' do
expect(build.reload.job_archive).not_to be_nil expect(build.reload.artifacts_archive).not_to be_nil
end end
end end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment