Commit 84e7ea12 authored by David Fernandez's avatar David Fernandez

Remove `safe_find_or_create_by!` usage

from the `Packages::CreatePackageService`.

`find_or_create_by!` is not atomic but we can live with that downside.
See: https://gitlab.com/gitlab-org/gitlab/-/issues/338947#note_659335940

Changelog: performance
parent 2a93b6af
...@@ -5,15 +5,19 @@ module Packages ...@@ -5,15 +5,19 @@ module Packages
protected protected
def find_or_create_package!(package_type, name: params[:name], version: params[:version]) def find_or_create_package!(package_type, name: params[:name], version: params[:version])
# safe_find_or_create_by! was originally called here.
# We merely switched to `find_or_create_by!`
# rubocop: disable CodeReuse/ActiveRecord
project project
.packages .packages
.with_package_type(package_type) .with_package_type(package_type)
.safe_find_or_create_by!(name: name, version: version) do |package| .find_or_create_by!(name: name, version: version) do |package|
package.status = params[:status] if params[:status] package.status = params[:status] if params[:status]
package.creator = package_creator package.creator = package_creator
add_build_info(package) add_build_info(package)
end end
# rubocop: enable CodeReuse/ActiveRecord
end end
def create_package!(package_type, attrs = {}) def create_package!(package_type, attrs = {})
......
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