Commit 38982136 authored by Douwe Maan's avatar Douwe Maan

Decrease memory use and increase performance of Google Code importer.

parent 7d98c884
......@@ -62,24 +62,7 @@ module Gitlab
def import_issues
return unless repo.issues
last_id = 0
deleted_issues = []
repo.issues.each do |raw_issue|
while raw_issue["id"] > last_id + 1
last_id += 1
issue = project.issues.create!(
title: "Deleted issue",
description: "*This issue has been deleted*",
author_id: project.creator_id,
state: "closed"
)
deleted_issues << issue
end
last_id = raw_issue["id"]
while raw_issue = repo.issues.shift
author = user_map[raw_issue["author"]["name"]]
date = DateTime.parse(raw_issue["published"]).to_formatted_s(:long)
......@@ -116,7 +99,8 @@ module Gitlab
end
end
issue = project.issues.create!(
issue = Issue.create!(
project_id: project.id,
title: raw_issue["title"],
description: body,
author_id: project.creator_id,
......@@ -125,14 +109,17 @@ module Gitlab
)
issue.add_labels_by_names(labels)
import_issue_comments(issue, comments)
if issue.iid != raw_issue["id"]
issue.update_attribute(:iid, raw_issue["id"])
end
deleted_issues.each(&:destroy!)
import_issue_comments(issue, comments)
end
end
def import_issue_comments(issue, comments)
comments.each do |raw_comment|
Note.transaction do
while raw_comment = comments.shift
next if raw_comment.has_key?("deletedBy")
content = format_content(raw_comment["content"])
......@@ -153,13 +140,17 @@ module Gitlab
attachments
)
issue.notes.create!(
# Needs to match order of `comment_columns` below.
Note.create!(
project_id: project.id,
noteable_type: "Issue",
noteable_id: issue.id,
author_id: project.creator_id,
note: body
)
end
end
end
def nice_label_color(name)
case name
......@@ -236,7 +227,7 @@ module Gitlab
def create_label(name)
color = nice_label_color(name)
project.labels.create!(name: name, color: color)
Label.create!(project_id: project.id, name: name, color: color)
end
def format_content(raw_content)
......
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