Commit 956768f5 authored by Stan Hu's avatar Stan Hu

Merge branch '10io-fix-nuget-package-file-size-update' into 'master'

Properly update nuget package file size

See merge request gitlab-org/gitlab!24687
parents e89c491b ab588fa7
......@@ -9,8 +9,6 @@ class Packages::PackageFile < ApplicationRecord
delegate :project, :project_id, to: :package
delegate :conan_file_type, to: :conan_file_metadatum
update_project_statistics project_statistics_name: :packages_size
belongs_to :package
has_one :conan_file_metadatum, inverse_of: :package_file
......@@ -36,13 +34,16 @@ class Packages::PackageFile < ApplicationRecord
with_replicator Geo::PackageFileReplicator
after_save :update_file_store, if: :saved_change_to_file?
after_save :update_file_metadata, if: :saved_change_to_file?
after_create_commit -> { replicator.publish_created_event }
def update_file_store
update_project_statistics project_statistics_name: :packages_size
def update_file_metadata
# The file.object_store is set during `uploader.store!`
# which happens after object is inserted/updated
self.update_column(:file_store, file.object_store)
self.update_column(:size, file.size) unless file.size == self.size
end
def log_geo_deleted_event
......
......@@ -34,5 +34,26 @@ RSpec.describe Packages::PackageFile, type: :model do
it_behaves_like 'UpdateProjectStatistics' do
subject { build(:package_file, :jar, size: 42) }
before do
allow_any_instance_of(Packages::PackageFileUploader).to receive(:size).and_return(42)
end
end
describe '#update_file_metadata callback' do
let(:package_file) { build(:package_file, :nuget, file_store: 0, size: nil) }
subject { package_file.save! }
it 'updates metadata columns' do
expect(package_file)
.to receive(:update_file_metadata)
.and_call_original
subject
expect(package_file.file_store).to eq 1
expect(package_file.size).to eq 3513
end
end
end
......@@ -82,6 +82,10 @@ describe Packages::Conan::CreatePackageFileService do
UploadedFile.new(file_path, filename: File.basename(file_path))
end
before do
allow_any_instance_of(Packages::PackageFileUploader).to receive(:size).and_return(128)
end
it_behaves_like 'a valid package_file'
it_behaves_like 'a valid recipe_file'
end
......@@ -91,6 +95,10 @@ describe Packages::Conan::CreatePackageFileService do
stub_package_file_object_storage(direct_upload: true)
end
before do
allow_any_instance_of(Packages::PackageFileUploader).to receive(:size).and_return(128)
end
let(:tmp_object) do
fog_connection.directories.new(key: 'packages').files.create(
key: "tmp/uploads/#{file_name}",
......
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