Commit 8645c763 authored by nmilojevic1's avatar nmilojevic1

Preload project, user and group to reuse objects

parent 2be380d2
......@@ -34,6 +34,8 @@ module Gitlab
PROJECT_REFERENCES = %w[project_id source_project_id target_project_id].freeze
GROUP_REFERENCES = %w[group_id].freeze
BUILD_MODELS = %i[Ci::Build commit_status].freeze
IMPORTED_OBJECT_MAX_RETRIES = 5.freeze
......@@ -89,7 +91,13 @@ module Gitlab
setup_models
generate_imported_object
object = generate_imported_object
# We preload the project, user, and group to re-use objects
object = preload_keys(object, PROJECT_REFERENCES, @project)
object = preload_keys(object, GROUP_REFERENCES, @project.group)
object = preload_keys(object, USER_REFERENCES, @user)
object
end
def self.overrides
......@@ -122,6 +130,19 @@ module Gitlab
remove_encrypted_attributes!
end
def preload_keys(object, references, value)
references.each do |key|
setter = "#{key.delete_suffix('_id')}=".to_sym
next unless object.respond_to?(key) && object.respond_to?(setter)
if object.public_send(key) == value&.id
object.public_send(setter, value)
end
end
object
end
def update_user_references
USER_REFERENCES.each do |reference|
if @relation_hash[reference]
......
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