From a0e62c9fb764dd09b686549d55986a8cb478c5a3 Mon Sep 17 00:00:00 2001 From: Erick Crager Date: Sat, 29 Oct 2022 09:20:21 -0500 Subject: [PATCH] Create new method on Batch granting control over count/sum updates. Previously, performance when adding many entries to the same batch could become quite poor, and some users only need batches counts and totals up to date at the time of rendering the NACHA file. With this new method, users who need constant batch counts and totals updated can still call updateBatchValues() after every addEntry() and those who don't can enjoy much improved file generation time. --- lib/batch/index.js | 2 ++ lib/file/index.js | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/batch/index.js b/lib/batch/index.js index bfa0eca..268174d 100644 --- a/lib/batch/index.js +++ b/lib/batch/index.js @@ -85,7 +85,9 @@ Batch.prototype.addEntry = function(entry) { // Add the new entry to the entries array this._entries.push(entry); +}; +Batch.prototype.updateBatchValues = function() { // Update the batch values like total debit and credit $ amounts var entryHash = 0; var totalDebit = 0; diff --git a/lib/file/index.js b/lib/file/index.js index bb74223..e507e81 100644 --- a/lib/file/index.js +++ b/lib/file/index.js @@ -105,7 +105,8 @@ File.prototype.generateBatches = function(done1) { var totalDebit = 0; var totalCredit = 0; - async.each(this._batches, function(batch, done2) { + async.each(this._batches, function(batch, done2) { + batch.updateBatchValues(); totalDebit += batch.control.totalDebit.value; totalCredit += batch.control.totalCredit.value;