Commit 0a294698 authored by Lin Jen-Shin's avatar Lin Jen-Shin

Just save the size in total rather than individual files

Feedback:
https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/4964#note_12741046
parent fe0c59d2
...@@ -5,7 +5,6 @@ module Ci ...@@ -5,7 +5,6 @@ module Ci
belongs_to :erased_by, class_name: 'User' belongs_to :erased_by, class_name: 'User'
serialize :options serialize :options
serialize :artifacts_sizes, JSON
validates :coverage, numericality: true, allow_blank: true validates :coverage, numericality: true, allow_blank: true
validates_presence_of :ref validates_presence_of :ref
...@@ -329,19 +328,13 @@ module Ci ...@@ -329,19 +328,13 @@ module Ci
artifacts? && artifacts_metadata.exists? artifacts? && artifacts_metadata.exists?
end end
def artifacts_metadata_sizes
return unless artifacts_metadata?
entries = new_artifacts_metadata('', recursive: true).find_entries!
entries.inject({}) do |result, (path, metadata)|
result[path] = metadata[:size] if metadata[:size]
result
end
end
def artifacts_metadata_entry(path, **options) def artifacts_metadata_entry(path, **options)
new_artifacts_metadata(path, **options).to_entry metadata = Gitlab::Ci::Build::Artifacts::Metadata.new(
artifacts_metadata.path,
path,
**options)
metadata.to_entry
end end
def erase_artifacts! def erase_artifacts!
...@@ -387,13 +380,6 @@ module Ci ...@@ -387,13 +380,6 @@ module Ci
private private
def new_artifacts_metadata(path, **options)
Gitlab::Ci::Build::Artifacts::Metadata.new(
artifacts_metadata.path,
path,
**options)
end
def erase_trace! def erase_trace!
self.trace = nil self.trace = nil
end end
......
# See http://doc.gitlab.com/ce/development/migration_style_guide.html # See http://doc.gitlab.com/ce/development/migration_style_guide.html
# for more information on how to write migrations for GitLab. # for more information on how to write migrations for GitLab.
class AddArtifactsSizesToCiBuilds < ActiveRecord::Migration class AddArtifactsSizeToCiBuilds < ActiveRecord::Migration
include Gitlab::Database::MigrationHelpers include Gitlab::Database::MigrationHelpers
def change def change
# Or :json if under PostgreSQL? add_column(:ci_builds, :artifacts_size, :integer)
add_column(:ci_builds, :artifacts_sizes, :text)
end end
end end
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20160620115026) do ActiveRecord::Schema.define(version: 20160628085157) do
# These are extensions that must be enabled in order to support this database # These are extensions that must be enabled in order to support this database
enable_extension "plpgsql" enable_extension "plpgsql"
...@@ -163,6 +163,7 @@ ActiveRecord::Schema.define(version: 20160620115026) do ...@@ -163,6 +163,7 @@ ActiveRecord::Schema.define(version: 20160620115026) do
t.datetime "erased_at" t.datetime "erased_at"
t.string "environment" t.string "environment"
t.datetime "artifacts_expire_at" t.datetime "artifacts_expire_at"
t.integer "artifacts_size"
end end
add_index "ci_builds", ["commit_id", "stage_idx", "created_at"], name: "index_ci_builds_on_commit_id_and_stage_idx_and_created_at", using: :btree add_index "ci_builds", ["commit_id", "stage_idx", "created_at"], name: "index_ci_builds_on_commit_id_and_stage_idx_and_created_at", using: :btree
......
...@@ -147,7 +147,7 @@ module Ci ...@@ -147,7 +147,7 @@ module Ci
build.artifacts_file = artifacts build.artifacts_file = artifacts
build.artifacts_metadata = metadata build.artifacts_metadata = metadata
build.artifacts_expire_in = params['expire_in'] build.artifacts_expire_in = params['expire_in']
build.artifacts_sizes = build.artifacts_metadata_sizes build.artifacts_size = artifacts.size
if build.save if build.save
present(build, with: Entities::BuildDetails) present(build, with: Entities::BuildDetails)
......
...@@ -344,14 +344,11 @@ describe Ci::API::API do ...@@ -344,14 +344,11 @@ describe Ci::API::API do
context 'should post artifacts file and metadata file' do context 'should post artifacts file and metadata file' do
let!(:artifacts) { file_upload } let!(:artifacts) { file_upload }
let!(:metadata) do let!(:metadata) { file_upload2 }
fixture_file_upload(
Rails.root + 'spec/fixtures/ci_build_artifacts_metadata.gz')
end
let(:stored_artifacts_file) { build.reload.artifacts_file.file } let(:stored_artifacts_file) { build.reload.artifacts_file.file }
let(:stored_metadata_file) { build.reload.artifacts_metadata.file } let(:stored_metadata_file) { build.reload.artifacts_metadata.file }
let(:stored_artifacts_sizes) { build.reload.artifacts_sizes } let(:stored_artifacts_size) { build.reload.artifacts_size }
before do before do
post(post_url, post_data, headers_with_token) post(post_url, post_data, headers_with_token)
...@@ -369,12 +366,7 @@ describe Ci::API::API do ...@@ -369,12 +366,7 @@ describe Ci::API::API do
expect(response).to have_http_status(201) expect(response).to have_http_status(201)
expect(stored_artifacts_file.original_filename).to eq(artifacts.original_filename) expect(stored_artifacts_file.original_filename).to eq(artifacts.original_filename)
expect(stored_metadata_file.original_filename).to eq(metadata.original_filename) expect(stored_metadata_file.original_filename).to eq(metadata.original_filename)
expect(stored_artifacts_sizes).to eq( expect(stored_artifacts_size).to eq(71759)
'ci_artifacts.txt' => 27,
'other_artifacts_0.1.2/another-subdirectory/banana_sample.gif' => 71759,
'other_artifacts_0.1.2/doc_sample.txt' => 1314,
'rails_sample.jpg' => 35255,
'tests_encoding/utf8 test dir ✓/regular_file_2' => 7)
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