From 07128d336838ac28ea8b1ea0e82674cbd0864c38 Mon Sep 17 00:00:00 2001 From: Brock Wilcox Date: Sun, 18 Jan 2026 10:31:19 -0500 Subject: [PATCH 1/2] Switch to in-memory item selection to speed up export --- app/services/exports/export_distributions_csv_service.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/services/exports/export_distributions_csv_service.rb b/app/services/exports/export_distributions_csv_service.rb index 10e831be07..c7cf938f5c 100644 --- a/app/services/exports/export_distributions_csv_service.rb +++ b/app/services/exports/export_distributions_csv_service.rb @@ -1,3 +1,5 @@ +require 'csv' + module Exports class ExportDistributionsCSVService include DistributionHelper @@ -135,7 +137,8 @@ def build_row_data(distribution) row = base_table.values.map { |closure| closure.call(distribution) } item_names.each do |item_name| - line_items = distribution.line_items.where(item: @organization.items.find_by(name: item_name)) + # We are doing this in-memory so that we can use the already-loaded line item records + line_items = distribution.line_items.select { |item| item.name == item_name } row << line_items.sum(&:quantity) row << Money.new(line_items.sum(&:value_per_line_item)) if @organization.include_in_kind_values_in_exported_files From 4f251c4b08f495b05b16f92fb2417383b1d87c3e Mon Sep 17 00:00:00 2001 From: Brock Wilcox Date: Sun, 18 Jan 2026 10:39:33 -0500 Subject: [PATCH 2/2] Apply suggestion from @scooter-dangle Co-authored-by: Scott Steele --- app/services/exports/export_distributions_csv_service.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/services/exports/export_distributions_csv_service.rb b/app/services/exports/export_distributions_csv_service.rb index c7cf938f5c..101ea2804d 100644 --- a/app/services/exports/export_distributions_csv_service.rb +++ b/app/services/exports/export_distributions_csv_service.rb @@ -1,3 +1,5 @@ +# Don't technically need to pull in csv for the code itself, +# but this ensures that the unit test can run in isolation require 'csv' module Exports