summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Lopez <james@jameslopez.es>2017-09-03 19:16:18 +0200
committerJames Lopez <james@jameslopez.es>2017-09-05 17:47:44 +0200
commit4a9dcfdc721ff6dd5926be5f20a75a691a5e85f0 (patch)
tree820cd469b7076ba1ddd0ef53763770b947b295cd
parenta54c50d1469737372398380f819223062bc27f21 (diff)
downloadgitlab-ce-4a9dcfdc721ff6dd5926be5f20a75a691a5e85f0.tar.gz
enable AR caching, refactor tree hash loop
-rw-r--r--lib/gitlab/import_export/project_tree_restorer.rb39
1 files changed, 27 insertions, 12 deletions
diff --git a/lib/gitlab/import_export/project_tree_restorer.rb b/lib/gitlab/import_export/project_tree_restorer.rb
index 3c9598887bf..eeb3024c83a 100644
--- a/lib/gitlab/import_export/project_tree_restorer.rb
+++ b/lib/gitlab/import_export/project_tree_restorer.rb
@@ -23,8 +23,10 @@ module Gitlab
@project_members = @tree_hash.delete('project_members')
- ActiveRecord::Base.no_touching do
- create_relations
+ ActiveRecord::Base.uncached do
+ ActiveRecord::Base.no_touching do
+ create_relations
+ end
end
rescue => e
@shared.error(e)
@@ -52,6 +54,7 @@ module Gitlab
@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
@@ -82,6 +85,10 @@ module Gitlab
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 = nil
+ relation_hash_batch = nil
@restored_project = Project.find_by_id(@project_id)
end
@@ -117,20 +124,28 @@ module Gitlab
relation_key = relation.keys.first.to_s
return if tree_hash[relation_key].blank?
- [tree_hash[relation_key]].flatten.each do |relation_item|
- relation.values.flatten.each do |sub_relation|
- # We just use author to get the user ID, do not attempt to create an instance.
- next if sub_relation == :author
+ tree_array = [tree_hash[relation_key]].flatten
- create_sub_relations(sub_relation, relation_item, false) if sub_relation.is_a?(Hash)
+ while relation_item = tree_array.shift
+ relation.values.flatten.each do |sub_relation|
+ # We just use author to get the user ID, do not attempt to create an instance.
+ next if sub_relation == :author
- 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
+ create_sub_relations(sub_relation, relation_item, false) if sub_relation.is_a?(Hash)
- save_relation_hash([relation_item], relation_key) if save
- tree_hash.delete(relation_key) if save
+ 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
+
+ if save
+ save_relation_hash([relation_item], relation_key)
+ end
+
+ tree_hash[relation_key].delete(relation_item) if save
+ relation_item = nil
end
+
+ tree_hash.delete(relation_key) if save
end
def assign_relation_hash(relation_item, sub_relation)