summaryrefslogtreecommitdiff
path: root/src/operations/pending.ts
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2020-05-11 18:03:25 +0530
committerFlorian Dold <florian.dold@gmail.com>2020-05-11 18:03:25 +0530
commit5d6192b0cd356f7e56fa8d6193a2e74233a52f4b (patch)
tree0360ba1d39e6ff081e25045652f457faca8cb879 /src/operations/pending.ts
parent7e947ca2cdd8e66ea49822acbad81e7d35289c0a (diff)
downloadwallet-core-5d6192b0cd356f7e56fa8d6193a2e74233a52f4b.tar.gz
wallet-core-5d6192b0cd356f7e56fa8d6193a2e74233a52f4b.tar.bz2
wallet-core-5d6192b0cd356f7e56fa8d6193a2e74233a52f4b.zip
make planchet management during withdrawal O(n) instead of O(n^2)
Diffstat (limited to 'src/operations/pending.ts')
-rw-r--r--src/operations/pending.ts16
1 files changed, 10 insertions, 6 deletions
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<void> {
- 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);