commit c3dbb3a5d578a8e1df6d69f892888e2a9460ddbd
parent 2db6888c511117a980a04159117c9e9db38e1c05
Author: Florian Dold <florian@dold.me>
Date: Tue, 19 Dec 2023 00:06:26 +0100
wallet-core: prioritize pending tasks
Diffstat:
2 files changed, 30 insertions(+), 2 deletions(-)
diff --git 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
@@ -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<PendingOperationsResponse> {
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;
}