Commit 40b004b9 authored by James Edwards-Jones's avatar James Edwards-Jones

CSV export minor improvements

parent c2913dc3
......@@ -6,6 +6,8 @@ class Projects::IssuesController < Projects::ApplicationController
include IssuableCollections
include SpammableActions
prepend_before_action :authenticate_user!, only: [:export_csv]
before_action :redirect_to_external_issue_tracker, only: [:index, :new]
before_action :module_enabled
before_action :issue, only: [:edit, :update, :show, :referenced_merge_requests,
......
......@@ -179,11 +179,11 @@ module Issuable
end
def labels_hash
eager_load(:labels).pluck(:id, 'labels.title').inject({}) do |memo, (issue_id, label)|
memo[issue_id] ||= []
memo[issue_id] << label
memo
issue_labels = Hash.new { |h, k| h[k] = [] }
eager_load(:labels).pluck(:id, 'labels.title').each do |issue_id, label|
issue_labels[issue_id] << label
end
issue_labels
end
# Includes table keys in group by clause when sorting
......
module Issues
class ExportCsvService
include Rails.application.routes.url_helpers
include Gitlab::Routing.url_helpers
include GitlabRoutingHelper
# Target attachment size before base64 encoding
......
......@@ -31,7 +31,7 @@ class CsvBuilder
tempfile = Tempfile.new('csv_export')
csv = CSV.new(tempfile)
write_csv(csv) do
write_csv csv, until_condition: -> do
truncate_after_bytes && tempfile.size > truncate_after_bytes
end
......@@ -86,7 +86,7 @@ class CsvBuilder
end
end
def write_csv(csv, &until_block)
def write_csv(csv, until_condition:)
csv << headers
@collection.find_each do |object|
......@@ -94,7 +94,7 @@ class CsvBuilder
@rows_written += 1
if yield
if until_condition.call
@truncated = true
break
end
......
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