From 49dbef5054ac84332d852b16a9f26a7709117726 Mon Sep 17 00:00:00 2001 From: Vincent Pochet Date: Tue, 28 May 2024 16:32:13 +0200 Subject: [PATCH] fix(current-usage): Manage connection pools with parallel threads --- app/services/invoices/customer_usage_service.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/services/invoices/customer_usage_service.rb b/app/services/invoices/customer_usage_service.rb index c8bae62e765..0219b80e12f 100644 --- a/app/services/invoices/customer_usage_service.rb +++ b/app/services/invoices/customer_usage_service.rb @@ -67,7 +67,9 @@ def add_charge_fees .order(Arel.sql('lower(unaccent(billable_metrics.name)) ASC')) invoice.fees = Parallel.flat_map(query.all, in_threads: ENV['LAGO_PARALLEL_THREADS_COUNT']&.to_i || 1) do |charge| - charge_usage(charge) + ActiveRecord::Base.connection_pool.with_connection do + charge_usage(charge) + end end end