Skip to content

Commit

Permalink
Merge pull request #1830 from fabiosegalla/master
Browse files Browse the repository at this point in the history
#ruby's #flat_map is much faster than combining #map and #flatten.
  • Loading branch information
caboteria committed Nov 24, 2013
2 parents e742099 + 7ab1615 commit 155493b
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/rails_admin/support/csv_converter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ def to_csv(options)
csv << @fields.map do |field|
output(::I18n.t('admin.export.csv.header_for_root_methods', :name => field.label, :model => @abstract_model.pretty_name))
end +
@associations.map do |association_name, option_hash|
@associations.flat_map do |association_name, option_hash|
option_hash[:fields].map do |field|
output(::I18n.t('admin.export.csv.header_for_association_methods', :name => field.label, :association => option_hash[:association].label))
end
end.flatten
end
end
method = @objects.respond_to?(:find_each) ? :find_each : :each
@objects.send(method) do |o|
Expand All @@ -72,13 +72,13 @@ def to_csv(options)
csv << @fields.map do |field|
output(field.with(:object => o).export_value)
end +
@associations.map do |association_name, option_hash|
@associations.flat_map do |association_name, option_hash|

associated_objects = [o.send(association_name)].flatten.compact
option_hash[:fields].map do |field|
output(associated_objects.map{ |ao| field.with(:object => ao).export_value.presence || @empty }.join(','))
end
end.flatten
end
end
end

Expand Down

0 comments on commit 155493b

Please sign in to comment.