From 5d6192b0cd356f7e56fa8d6193a2e74233a52f4b Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Mon, 11 May 2020 18:03:25 +0530 Subject: make planchet management during withdrawal O(n) instead of O(n^2) --- src/operations/pending.ts | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'src/operations/pending.ts') diff --git a/src/operations/pending.ts b/src/operations/pending.ts index a797763bf..14072633c 100644 --- a/src/operations/pending.ts +++ b/src/operations/pending.ts @@ -246,7 +246,7 @@ async function gatherWithdrawalPending( resp: PendingOperationsResponse, onlyDue = false, ): Promise { - await tx.iter(Stores.withdrawalGroups).forEach((wsr) => { + await tx.iter(Stores.withdrawalGroups).forEachAsync(async (wsr) => { if (wsr.timestampFinish) { return; } @@ -258,11 +258,14 @@ async function gatherWithdrawalPending( if (onlyDue && wsr.retryInfo.nextRetry.t_ms > now.t_ms) { return; } - const numCoinsWithdrawn = wsr.withdrawn.reduce( - (a, x) => a + (x ? 1 : 0), - 0, - ); - const numCoinsTotal = wsr.withdrawn.length; + let numCoinsWithdrawn = 0; + let numCoinsTotal = 0; + await tx.iterIndexed(Stores.planchets.byGroup, wsr.withdrawalGroupId).forEach((x) => { + numCoinsTotal++; + if (x.withdrawalDone) { + numCoinsWithdrawn++; + } + }); resp.pendingOperations.push({ type: PendingOperationType.Withdraw, givesLifeness: true, @@ -443,6 +446,7 @@ export async function getPendingOperations( Stores.tips, Stores.purchases, Stores.recoupGroups, + Stores.planchets, ], async (tx) => { const walletBalance = await getBalancesInsideTransaction(ws, tx); -- cgit v1.2.3