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 << @attributes
logs.each do |log|
logs.find_each do |log|
csv << @attributes.map { |attribute| value(attribute, log) }
end
end

2
app/services/csv/sales_log_csv_service.rb

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

10
app/services/csv/scheme_csv_service.rb

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

Loading…
Cancel
Save