Skip to content

Commit c0dd351

Browse files
committed
Make the variables used in recursive function global
This is so we dont overflow the stack when there are lot of transactions being rerun.
1 parent d314e72 commit c0dd351

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/api/transactions.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ export async function rerunTransactions(ctx) {
282282
}
283283
}
284284

285-
let transactionsToRerun
285+
let transactionsToRerun, taskObject, task
286286

287287
async function createRerunTasks(filters, batchSize, email, page, pages, pauseQueue, filterLimit) {
288288
transactionsToRerun = await TransactionModelAPI.find(filters, {_id: 1})
@@ -298,7 +298,7 @@ async function createRerunTasks(filters, batchSize, email, page, pages, pauseQue
298298
tid: trans._id
299299
}})
300300

301-
const taskObject = {}
301+
taskObject = {}
302302
taskObject.remainingTransactions = transactionsToRerun.length
303303
taskObject.user = email
304304
taskObject.transactions = transactionsToRerun
@@ -309,14 +309,16 @@ async function createRerunTasks(filters, batchSize, email, page, pages, pauseQue
309309
taskObject.status = 'Paused'
310310
}
311311

312-
const task = await new TaskModelAPI(taskObject).save()
312+
task = await new TaskModelAPI(taskObject).save()
313313

314314
logger.info(`Rerun task with id ${task._id} created!`)
315315

316316
if (page < pages) {
317317
return createRerunTasks(filters, batchSize, email, ++page, pages, pauseQueue, filterLimit)
318318
} else {
319319
transactionsToRerun = null
320+
task = null
321+
taskObject = null
320322
return
321323
}
322324
}

0 commit comments

Comments
 (0)