From c3dbb3a5d578a8e1df6d69f892888e2a9460ddbd Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Tue, 19 Dec 2023 00:06:26 +0100 Subject: wallet-core: prioritize pending tasks --- .../taler-wallet-core/src/operations/exchanges.ts | 6 ++++- .../taler-wallet-core/src/operations/pending.ts | 26 +++++++++++++++++++++- 2 files changed, 30 insertions(+), 2 deletions(-) (limited to 'packages') diff --git a/packages/taler-wallet-core/src/operations/exchanges.ts b/packages/taler-wallet-core/src/operations/exchanges.ts index fe6060499..f4ee80e9e 100644 --- a/packages/taler-wallet-core/src/operations/exchanges.ts +++ b/packages/taler-wallet-core/src/operations/exchanges.ts @@ -806,7 +806,11 @@ export async function fetchFreshExchange( const nextUpdate = timestampOptionalAbsoluteFromDb( oldExchange.nextUpdateStamp, ); - if (nextUpdate == null || AbsoluteTime.isExpired(nextUpdate)) { + if ( + nextUpdate == null || + AbsoluteTime.isExpired(nextUpdate) || + oldExchange.updateStatus !== ExchangeEntryDbUpdateStatus.Ready + ) { needsUpdate = true; } } diff --git a/packages/taler-wallet-core/src/operations/pending.ts b/packages/taler-wallet-core/src/operations/pending.ts index e554a9b0f..76b9fd801 100644 --- a/packages/taler-wallet-core/src/operations/pending.ts +++ b/packages/taler-wallet-core/src/operations/pending.ts @@ -735,11 +735,27 @@ async function gatherPeerPushCreditPending( ); } +const taskPrio: { [X in PendingTaskType]: number } = { + [PendingTaskType.Deposit]: 2, + [PendingTaskType.ExchangeUpdate]: 1, + [PendingTaskType.PeerPullCredit]: 2, + [PendingTaskType.PeerPullDebit]: 2, + [PendingTaskType.PeerPushCredit]: 2, + [PendingTaskType.Purchase]: 2, + [PendingTaskType.Recoup]: 3, + [PendingTaskType.RewardPickup]: 2, + [PendingTaskType.Refresh]: 3, + [PendingTaskType.Withdraw]: 3, + [PendingTaskType.ExchangeCheckRefresh]: 3, + [PendingTaskType.PeerPushDebit]: 2, + [PendingTaskType.Backup]: 4, +}; + export async function getPendingOperations( ws: InternalWalletState, ): Promise { const now = AbsoluteTime.now(); - return await ws.db + const resp = await ws.db .mktx((x) => [ x.backupProviders, x.exchanges, @@ -776,4 +792,12 @@ export async function getPendingOperations( await gatherPeerPushCreditPending(ws, tx, now, resp); return resp; }); + + resp.pendingOperations.sort((a, b) => { + let prioA = taskPrio[a.type]; + let prioB = taskPrio[b.type]; + return Math.sign(prioA - prioB); + }); + + return resp; } -- cgit v1.2.3