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