summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Lopez <james@jameslopez.es>2017-09-01 17:20:09 +0200
committerJames Lopez <james@jameslopez.es>2017-09-05 17:47:44 +0200
commit690b9865f48c41f16dd0c70b37dbcc66fee4c67c (patch)
treec231fcbd7031703386fff8172c687654d2478149
parent0085f5e0aef9e2d6379d2cbc03540c34dd43dc5a (diff)
downloadgitlab-ce-690b9865f48c41f16dd0c70b37dbcc66fee4c67c.tar.gz
some more performance refactoring
-rw-r--r--lib/gitlab/import_export/project_tree_restorer.rb45
1 files changed, 33 insertions, 12 deletions
diff --git a/lib/gitlab/import_export/project_tree_restorer.rb b/lib/gitlab/import_export/project_tree_restorer.rb
index 6fffed68c7e..a288b7a5b56 100644
--- a/lib/gitlab/import_export/project_tree_restorer.rb
+++ b/lib/gitlab/import_export/project_tree_restorer.rb
@@ -9,6 +9,7 @@ module Gitlab
@user = user
@shared = shared
@project = project
+ @project_id = project.id
end
def restore
@@ -48,24 +49,42 @@ module Gitlab
# the configuration yaml file too.
# Finally, it updates each attribute in the newly imported project.
def create_relations
- saved = []
+ @saved = []
default_relation_list.each do |relation|
next unless relation.is_a?(Hash) || @tree_hash[relation.to_s].present?
+ if relation.is_a?(Hash)
+ create_sub_relations(relation, @tree_hash)
+ else
+ relation_key = relation.is_a?(Hash) ? relation.keys.first : relation
+ relation_hash_list = @tree_hash[relation_key.to_s]
+ save_relation_hash(relation_hash_list, relation_key, saved)
+ end
- create_sub_relations(relation, @tree_hash) if relation.is_a?(Hash)
- relation_key = relation.is_a?(Hash) ? relation.keys.first : relation
- relation_hash_list = @tree_hash[relation_key.to_s]
+ # relation_key = relation.is_a?(Hash) ? relation.keys.first : relation
+ # relation_hash_list = @tree_hash[relation_key.to_s]
+ #
+ # next unless relation_hash_list
+ #
+ # if relation_hash_list.is_a?(Array)
+ # [relation_hash_list].flatten.each_slice(15) do |relation_hash_batch|
+ # save_relation_hash(relation_hash_batch, relation_key, saved)
+ # end
+ # else
+ # save_relation_hash(relation_hash_list, relation_key, saved)
+ # end
- next unless relation_hash_list
+ end
+ @saved.all?
+ end
- [relation_hash_list].flatten.each_slice(10) do |relation_hash_batch|
+ def save_relation_hash(relation_hash_batch, relation_key)
+ relation_hash = create_relation(relation_key, relation_hash_batch)
+ @saved << restored_project.append_or_update_attribute(relation_key, relation_hash)
+ @restored_project = nil
+ @project = nil
- relation_hash = create_relation(relation_key, relation_hash_batch)
- saved << restored_project.append_or_update_attribute(relation_key, relation_hash)
- end
- end
- saved.all?
+ @project = Project.find_by_id(@project_id)
end
def default_relation_list
@@ -80,7 +99,7 @@ module Gitlab
@project.update_columns(project_params)
@project
end
-git che
+
def project_params
@tree_hash.reject do |key, value|
# return params that are not 1 to many or 1 to 1 relations
@@ -110,6 +129,8 @@ git che
relation_hash, sub_relation = assign_relation_hash(relation_item, sub_relation)
relation_item[sub_relation.to_s] = create_relation(sub_relation, relation_hash) unless relation_hash.blank?
end
+
+ save_relation_hash(relation_item, relation_key)
end
end