Commit fa903956 authored by James Edwards-Jones's avatar James Edwards-Jones

Issues CSV avoids instantiating labels

parent 94e9d049
labels = @issues.eager_load(:labels).
pluck(:id, 'labels.title').
inject(Hash.new([])) do |memo, (issue_id, label)|
memo[issue_id] += [label]
memo
end
columns = { columns = {
'Issue ID' => 'iid', 'Issue ID' => 'iid',
'Title' => 'title', 'Title' => 'title',
...@@ -10,7 +17,7 @@ columns = { ...@@ -10,7 +17,7 @@ columns = {
'Created At (UTC)' => -> (issue) { issue.created_at&.strftime('%Y-%m-%d %H:%M:%S') }, 'Created At (UTC)' => -> (issue) { issue.created_at&.strftime('%Y-%m-%d %H:%M:%S') },
'Updated At (UTC)' => -> (issue) { issue.updated_at&.strftime('%Y-%m-%d %H:%M:%S') }, 'Updated At (UTC)' => -> (issue) { issue.updated_at&.strftime('%Y-%m-%d %H:%M:%S') },
'Milestone' => -> (issue) { issue.milestone&.title }, 'Milestone' => -> (issue) { issue.milestone&.title },
'Labels' => -> (issue) { issue.labels_array.sort_by(&:title).map(&:title).join(',').presence }, 'Labels' => -> (issue) { labels[issue.id].sort.join(',').presence }
} }
CsvBuilder.new(columns).render(@issues.includes(:author, :assignee, :labels)) CsvBuilder.new(columns).render(@issues.includes(:author, :assignee))
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