summaryrefslogtreecommitdiff
path: root/app/services/packages/nuget
diff options
context:
space:
mode:
Diffstat (limited to 'app/services/packages/nuget')
-rw-r--r--app/services/packages/nuget/create_dependency_service.rb2
-rw-r--r--app/services/packages/nuget/update_package_from_metadata_service.rb63
2 files changed, 50 insertions, 15 deletions
diff --git a/app/services/packages/nuget/create_dependency_service.rb b/app/services/packages/nuget/create_dependency_service.rb
index 62ab485c0fc..3fc42056d43 100644
--- a/app/services/packages/nuget/create_dependency_service.rb
+++ b/app/services/packages/nuget/create_dependency_service.rb
@@ -41,7 +41,7 @@ module Packages
}
end
- ::Gitlab::Database.bulk_insert(::Packages::Nuget::DependencyLinkMetadatum.table_name, rows.compact) # rubocop:disable Gitlab/BulkInsert
+ ::Gitlab::Database.main.bulk_insert(::Packages::Nuget::DependencyLinkMetadatum.table_name, rows.compact) # rubocop:disable Gitlab/BulkInsert
end
def raw_dependency_for(dependency)
diff --git a/app/services/packages/nuget/update_package_from_metadata_service.rb b/app/services/packages/nuget/update_package_from_metadata_service.rb
index 2d1733421fd..6ffe4f097f4 100644
--- a/app/services/packages/nuget/update_package_from_metadata_service.rb
+++ b/app/services/packages/nuget/update_package_from_metadata_service.rb
@@ -21,22 +21,11 @@ module Packages
try_obtain_lease do
@package_file.transaction do
- if existing_package
- package = link_to_existing_package
- elsif symbol_package?
- raise InvalidMetadataError, 'symbol package is invalid, matching package does not exist'
+ if use_new_package_file_updater?
+ new_execute
else
- package = update_linked_package
+ legacy_execute
end
-
- update_package(package)
-
- # Updating file_name updates the path where the file is stored.
- # We must pass the file again so that CarrierWave can handle the update
- @package_file.update!(
- file_name: package_filename,
- file: @package_file.file
- )
end
end
rescue ActiveRecord::RecordInvalid => e
@@ -45,6 +34,52 @@ module Packages
private
+ def new_execute
+ package_to_destroy = nil
+ target_package = @package_file.package
+
+ if existing_package
+ package_to_destroy = @package_file.package
+ target_package = existing_package
+ else
+ if symbol_package?
+ raise InvalidMetadataError, 'symbol package is invalid, matching package does not exist'
+ end
+
+ update_linked_package
+ end
+
+ update_package(target_package)
+
+ ::Packages::UpdatePackageFileService.new(@package_file, package_id: target_package.id, file_name: package_filename)
+ .execute
+
+ package_to_destroy&.destroy!
+ end
+
+ def legacy_execute
+ if existing_package
+ package = link_to_existing_package
+ elsif symbol_package?
+ raise InvalidMetadataError, 'symbol package is invalid, matching package does not exist'
+ else
+ package = update_linked_package
+ end
+
+ update_package(package)
+
+ # Updating file_name updates the path where the file is stored.
+ # We must pass the file again so that CarrierWave can handle the update
+ @package_file.update!(
+ file_name: package_filename,
+ file: @package_file.file
+ )
+ end
+
+ def use_new_package_file_updater?
+ ::Feature.enabled?(:packages_nuget_new_package_file_updater, @package_file.project, default_enabled: :yaml)
+ end
+
def update_package(package)
return if symbol_package?