diff options
author | Florian Dold <florian@dold.me> | 2022-01-11 21:00:12 +0100 |
---|---|---|
committer | Florian Dold <florian@dold.me> | 2022-01-11 22:15:56 +0100 |
commit | a74cdf05295764258fe9e7f66f73a442a9b46697 (patch) | |
tree | d1a662fede130abc1fa33cdbc96c081cc47b23cd /packages/taler-wallet-core/src/operations/pending.ts | |
parent | a05e891d6e1468fdd99f710301e286857a46aea3 (diff) | |
download | wallet-core-a74cdf05295764258fe9e7f66f73a442a9b46697.tar.xz |
fix DB indexing issues
Diffstat (limited to 'packages/taler-wallet-core/src/operations/pending.ts')
-rw-r--r-- | packages/taler-wallet-core/src/operations/pending.ts | 167 |
1 files changed, 89 insertions, 78 deletions
diff --git a/packages/taler-wallet-core/src/operations/pending.ts b/packages/taler-wallet-core/src/operations/pending.ts index e3d22bfe6..07c29e874 100644 --- a/packages/taler-wallet-core/src/operations/pending.ts +++ b/packages/taler-wallet-core/src/operations/pending.ts @@ -28,6 +28,7 @@ import { WalletStoresV1, BackupProviderStateTag, RefreshCoinStatus, + OperationStatus, } from "../db.js"; import { PendingOperationsResponse, @@ -37,6 +38,8 @@ import { import { getTimestampNow, isTimestampExpired, + j2s, + Logger, Timestamp, } from "@gnu-taler/taler-util"; import { InternalWalletState } from "../common.js"; @@ -82,33 +85,35 @@ async function gatherReservePending( now: Timestamp, resp: PendingOperationsResponse, ): Promise<void> { - await tx.reserves.iter().forEach((reserve) => { - const reserveType = reserve.bankInfo - ? ReserveType.TalerBankWithdraw - : ReserveType.Manual; - switch (reserve.reserveStatus) { - case ReserveRecordStatus.DORMANT: - // nothing to report as pending - break; - case ReserveRecordStatus.WAIT_CONFIRM_BANK: - case ReserveRecordStatus.QUERYING_STATUS: - case ReserveRecordStatus.REGISTERING_BANK: - resp.pendingOperations.push({ - type: PendingTaskType.Reserve, - givesLifeness: true, - timestampDue: reserve.retryInfo.nextRetry, - stage: reserve.reserveStatus, - timestampCreated: reserve.timestampCreated, - reserveType, - reservePub: reserve.reservePub, - retryInfo: reserve.retryInfo, - }); - break; - default: - // FIXME: report problem! - break; - } - }); + await tx.reserves.indexes.byStatus + .iter(OperationStatus.Pending) + .forEach((reserve) => { + const reserveType = reserve.bankInfo + ? ReserveType.TalerBankWithdraw + : ReserveType.Manual; + switch (reserve.reserveStatus) { + case ReserveRecordStatus.DORMANT: + // nothing to report as pending + break; + case ReserveRecordStatus.WAIT_CONFIRM_BANK: + case ReserveRecordStatus.QUERYING_STATUS: + case ReserveRecordStatus.REGISTERING_BANK: + resp.pendingOperations.push({ + type: PendingTaskType.Reserve, + givesLifeness: true, + timestampDue: reserve.retryInfo.nextRetry, + stage: reserve.reserveStatus, + timestampCreated: reserve.timestampCreated, + reserveType, + reservePub: reserve.reservePub, + retryInfo: reserve.retryInfo, + }); + break; + default: + // FIXME: report problem! + break; + } + }); } async function gatherRefreshPending( @@ -116,24 +121,26 @@ async function gatherRefreshPending( now: Timestamp, resp: PendingOperationsResponse, ): Promise<void> { - await tx.refreshGroups.iter().forEach((r) => { - if (r.timestampFinished) { - return; - } - if (r.frozen) { - return; - } - resp.pendingOperations.push({ - type: PendingTaskType.Refresh, - givesLifeness: true, - timestampDue: r.retryInfo.nextRetry, - refreshGroupId: r.refreshGroupId, - finishedPerCoin: r.statusPerCoin.map( - (x) => x === RefreshCoinStatus.Finished, - ), - retryInfo: r.retryInfo, + await tx.refreshGroups.indexes.byStatus + .iter(OperationStatus.Pending) + .forEach((r) => { + if (r.timestampFinished) { + return; + } + if (r.frozen) { + return; + } + resp.pendingOperations.push({ + type: PendingTaskType.Refresh, + givesLifeness: true, + timestampDue: r.retryInfo.nextRetry, + refreshGroupId: r.refreshGroupId, + finishedPerCoin: r.statusPerCoin.map( + (x) => x === RefreshCoinStatus.Finished, + ), + retryInfo: r.retryInfo, + }); }); - }); } async function gatherWithdrawalPending( @@ -144,29 +151,31 @@ async function gatherWithdrawalPending( now: Timestamp, resp: PendingOperationsResponse, ): Promise<void> { - await tx.withdrawalGroups.iter().forEachAsync(async (wsr) => { - if (wsr.timestampFinish) { - return; - } - let numCoinsWithdrawn = 0; - let numCoinsTotal = 0; - await tx.planchets.indexes.byGroup - .iter(wsr.withdrawalGroupId) - .forEach((x) => { - numCoinsTotal++; - if (x.withdrawalDone) { - numCoinsWithdrawn++; - } + await tx.withdrawalGroups.indexes.byStatus + .iter(OperationStatus.Pending) + .forEachAsync(async (wsr) => { + if (wsr.timestampFinish) { + return; + } + let numCoinsWithdrawn = 0; + let numCoinsTotal = 0; + await tx.planchets.indexes.byGroup + .iter(wsr.withdrawalGroupId) + .forEach((x) => { + numCoinsTotal++; + if (x.withdrawalDone) { + numCoinsWithdrawn++; + } + }); + resp.pendingOperations.push({ + type: PendingTaskType.Withdraw, + givesLifeness: true, + timestampDue: wsr.retryInfo.nextRetry, + withdrawalGroupId: wsr.withdrawalGroupId, + lastError: wsr.lastError, + retryInfo: wsr.retryInfo, }); - resp.pendingOperations.push({ - type: PendingTaskType.Withdraw, - givesLifeness: true, - timestampDue: wsr.retryInfo.nextRetry, - withdrawalGroupId: wsr.withdrawalGroupId, - lastError: wsr.lastError, - retryInfo: wsr.retryInfo, }); - }); } async function gatherProposalPending( @@ -199,20 +208,22 @@ async function gatherDepositPending( now: Timestamp, resp: PendingOperationsResponse, ): Promise<void> { - await tx.depositGroups.iter().forEach((dg) => { - if (dg.timestampFinished) { - return; - } - const timestampDue = dg.retryInfo?.nextRetry ?? getTimestampNow(); - resp.pendingOperations.push({ - type: PendingTaskType.Deposit, - givesLifeness: true, - timestampDue, - depositGroupId: dg.depositGroupId, - lastError: dg.lastError, - retryInfo: dg.retryInfo, + await tx.depositGroups.indexes.byStatus + .iter(OperationStatus.Pending) + .forEach((dg) => { + if (dg.timestampFinished) { + return; + } + const timestampDue = dg.retryInfo?.nextRetry ?? getTimestampNow(); + resp.pendingOperations.push({ + type: PendingTaskType.Deposit, + givesLifeness: true, + timestampDue, + depositGroupId: dg.depositGroupId, + lastError: dg.lastError, + retryInfo: dg.retryInfo, + }); }); - }); } async function gatherTipPending( |