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

parent 22a33d82
...@@ -95,10 +95,13 @@ module Github ...@@ -95,10 +95,13 @@ module Github
response.body.each do |raw| response.body.each do |raw|
begin begin
label = Github::Representation::Label.new(raw) representation = Github::Representation::Label.new(raw)
next if project.labels.where(title: label.title).exists?
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 rescue => e
error(:label, label.url, e.message) error(:label, label.url, e.message)
end end
...@@ -106,11 +109,6 @@ module Github ...@@ -106,11 +109,6 @@ module Github
url = response.rels[:next] url = response.rels[:next]
end end
# Cache labels
project.labels.select(:id, :title).find_each do |label|
cached[:label_ids][label.title] = label.id
end
end end
def fetch_milestones def fetch_milestones
......
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