Cache labels at the same time we fetch them from the GH API

This commit is contained in:
Douglas Barbosa Alexandre 2017-04-24 21:03:42 -03:00
parent 22a33d8256
commit 05255631ae
1 changed files with 6 additions and 8 deletions

View File

@ -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