Browse Source

feat: use find_each everywhere to speed up file generation time (#2092)

pull/2094/head
natdeanlewissoftwire 1 year ago committed by GitHub
parent
commit
925d30868f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      app/services/csv/lettings_log_csv_service.rb
  2. 2
      app/services/csv/sales_log_csv_service.rb
  3. 10
      app/services/csv/scheme_csv_service.rb

2
app/services/csv/lettings_log_csv_service.rb

@ -10,7 +10,7 @@ module Csv
CSV.generate(headers: true) do |csv| CSV.generate(headers: true) do |csv|
csv << @attributes csv << @attributes
logs.each do |log| logs.find_each do |log|
csv << @attributes.map { |attribute| value(attribute, log) } csv << @attributes.map { |attribute| value(attribute, log) }
end end
end end

2
app/services/csv/sales_log_csv_service.rb

@ -9,7 +9,7 @@ module Csv
CSV.generate(headers: true) do |csv| CSV.generate(headers: true) do |csv|
csv << @attributes csv << @attributes
logs.each do |log| logs.find_each do |log|
csv << @attributes.map { |attribute| value(attribute, log) } csv << @attributes.map { |attribute| value(attribute, log) }
end end
end end

10
app/services/csv/scheme_csv_service.rb

@ -13,18 +13,18 @@ module Csv
case @download_type case @download_type
when "schemes" when "schemes"
schemes.each do |scheme| schemes.find_each do |scheme|
csv << scheme_attributes.map { |attribute| scheme_value(attribute, scheme) } csv << scheme_attributes.map { |attribute| scheme_value(attribute, scheme) }
end end
when "locations" when "locations"
schemes.each do |scheme| schemes.find_each do |scheme|
scheme.locations.each do |location| scheme.locations.find_each do |location|
csv << [scheme.id_to_display] + location_attributes.map { |attribute| location_value(attribute, location) } csv << [scheme.id_to_display] + location_attributes.map { |attribute| location_value(attribute, location) }
end end
end end
when "combined" when "combined"
schemes.each do |scheme| schemes.find_each do |scheme|
scheme.locations.each do |location| scheme.locations.find_each do |location|
csv << scheme_attributes.map { |attribute| scheme_value(attribute, scheme) } + location_attributes.map { |attribute| location_value(attribute, location) } csv << scheme_attributes.map { |attribute| scheme_value(attribute, scheme) } + location_attributes.map { |attribute| location_value(attribute, location) }
end end
end end

Loading…
Cancel
Save