summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDouglas Barbosa Alexandre <dbalexandre@gmail.com>2017-04-24 21:03:42 -0300
committerDouglas Barbosa Alexandre <dbalexandre@gmail.com>2017-04-24 21:03:42 -0300
commit05255631ae2dad3b22796343453bb3288ca3dbff (patch)
treefd971ece4d999d3524d02c94473d3eab80beb28c
parent22a33d8256101b0a5f348ae93623d4b189a96d47 (diff)
downloadgitlab-ce-05255631ae2dad3b22796343453bb3288ca3dbff.tar.gz
Cache labels at the same time we fetch them from the GH API
-rw-r--r--lib/github/import.rb14
1 files changed, 6 insertions, 8 deletions
diff --git a/lib/github/import.rb b/lib/github/import.rb
index ba30ea0e2cd..641147c40e4 100644
--- a/lib/github/import.rb
+++ b/lib/github/import.rb
@@ -95,10 +95,13 @@ module Github
response.body.each do |raw|
begin
- label = Github::Representation::Label.new(raw)
- next if project.labels.where(title: label.title).exists?
+ representation = Github::Representation::Label.new(raw)
- project.labels.create!(title: label.title, color: label.color)
+ label = project.labels.find_or_create_by!(title: representation.title) do |label|
+ label.color = representation.color
+ end
+
+ cached[:label_ids][label.title] = label.id
rescue => e
error(:label, label.url, e.message)
end
@@ -106,11 +109,6 @@ module Github
url = response.rels[:next]
end
-
- # Cache labels
- project.labels.select(:id, :title).find_each do |label|
- cached[:label_ids][label.title] = label.id
- end
end
def fetch_milestones