mirror of
https://github.com/System-End/theseus.git
synced 2026-04-19 15:28:19 +00:00
preserve CSV row order in letter batch PDF generation
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
2c6356bbf1
commit
fdec07ff21
2 changed files with 5 additions and 12 deletions
|
|
@ -139,18 +139,11 @@ class Batch < ApplicationRecord
|
|||
tokens = items.map { |item| item[:token] }
|
||||
addresses_by_token = Address.where(import_token: tokens).index_by(&:import_token)
|
||||
|
||||
Parallel.each(items, in_threads: 8) do |item|
|
||||
begin
|
||||
address = addresses_by_token.fetch(item[:token])
|
||||
items.each do |item|
|
||||
address = addresses_by_token.fetch(item[:token])
|
||||
|
||||
ActiveRecord::Base.connection_pool.with_connection do
|
||||
ActiveRecord::Base.transaction do
|
||||
build_mapping(item[:row], address)
|
||||
end
|
||||
end
|
||||
rescue => e
|
||||
Rails.logger.error("Error creating associated records for address in batch #{id}: #{e.message}")
|
||||
raise
|
||||
ActiveRecord::Base.transaction do
|
||||
build_mapping(item[:row], address)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -380,7 +380,7 @@ class Letter::Batch < Batch
|
|||
return unless letters.any?
|
||||
|
||||
# Preload associations to avoid N+1 queries
|
||||
preloaded_letters = letters.includes(:address, :usps_mailer_id, :usps_indicium, :return_address)
|
||||
preloaded_letters = letters.order(:id).includes(:address, :usps_mailer_id, :usps_indicium, :return_address)
|
||||
|
||||
# Build options for label generation
|
||||
label_options = {}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue