gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[taler-wallet-core] branch master updated: wallet-core: always return at


From: gnunet
Subject: [taler-wallet-core] branch master updated: wallet-core: always return at least 'limit' transactions if available
Date: Fri, 04 Oct 2024 15:18:38 +0200

This is an automated email from the git hooks/post-receive script.

dold pushed a commit to branch master
in repository wallet-core.

The following commit(s) were added to refs/heads/master by this push:
     new 988f551fa wallet-core: always return at least 'limit' transactions if 
available
988f551fa is described below

commit 988f551fa38eb48c52b82af897eb1db93826953d
Author: Florian Dold <florian@dold.me>
AuthorDate: Fri Oct 4 15:18:34 2024 +0200

    wallet-core: always return at least 'limit' transactions if available
---
 packages/taler-wallet-core/src/transactions.ts | 56 +++++++++++++-------------
 1 file changed, 29 insertions(+), 27 deletions(-)

diff --git a/packages/taler-wallet-core/src/transactions.ts 
b/packages/taler-wallet-core/src/transactions.ts
index 55838e4f2..4d3dbb45d 100644
--- a/packages/taler-wallet-core/src/transactions.ts
+++ b/packages/taler-wallet-core/src/transactions.ts
@@ -26,7 +26,6 @@ import {
   AbsoluteTime,
   Amounts,
   assertUnreachable,
-  checkLogicInvariant,
   GetTransactionsV2Request,
   j2s,
   Logger,
@@ -219,16 +218,31 @@ function checkFilterIncludes(
   return included;
 }
 
-function addFiltered(
+async function addFiltered(
+  wex: WalletExecutionContext,
+  tx: WalletDbAllStoresReadOnlyTransaction,
   req: GetTransactionsV2Request | undefined,
-  target: TransactionMetaRecord[],
+  target: Transaction[],
   source: TransactionMetaRecord[],
-): void {
+): Promise<number> {
+  let numAdded: number = 0;
   for (const mtx of source) {
+    if (req?.limit != null && target.length >= Math.abs(req.limit)) {
+      break;
+    }
     if (checkFilterIncludes(req, mtx)) {
-      target.push(mtx);
+      const ctx = await getContextForTransaction(wex, mtx.transactionId);
+      const txDetails = await ctx.lookupFullTransaction(tx);
+      // FIXME: This means that in some cases we can return fewer transactions
+      // than requested.
+      if (!txDetails) {
+        continue;
+      }
+      numAdded += 1;
+      target.push(txDetails);
     }
   }
+  return numAdded;
 }
 
 /**
@@ -328,7 +342,6 @@ export async function getTransactionsV2(
   const resultTransactions: Transaction[] = [];
 
   await wex.db.runAllStoresReadOnlyTx({}, async (tx) => {
-    let mtxs: TransactionMetaRecord[] = [];
     let forwards =
       transactionsRequest?.limit == null || transactionsRequest.limit >= 0;
     let limit =
@@ -341,7 +354,7 @@ export async function getTransactionsV2(
       // Fast path for returning *everything* that matches the filter.
       // FIXME: We could use the DB for filtering here
       const res = await tx.transactionsMeta.indexes.byStatus.getAll();
-      addFiltered(transactionsRequest, mtxs, res);
+      await addFiltered(wex, tx, transactionsRequest, resultTransactions, res);
     } else if (!forwards) {
       // Descending, backwards request.
       // Slow implementation. Doing it properly would require using cursors,
@@ -358,15 +371,13 @@ export async function getTransactionsV2(
       } else {
         start = 0;
       }
-      let numAdded = 0;
       for (let i = start; i < res.length; i++) {
-        if (limit != null && numAdded >= limit) {
+        if (limit != null && resultTransactions.length >= limit) {
           break;
         }
-        if (checkFilterIncludes(transactionsRequest, res[i])) {
-          mtxs.push(res[i]);
-          numAdded += 1;
-        }
+        await addFiltered(wex, tx, transactionsRequest, resultTransactions, [
+          res[i],
+        ]);
       }
     } else {
       // Forward request
@@ -379,8 +390,11 @@ export async function getTransactionsV2(
           query,
           limit,
         );
-        addFiltered(transactionsRequest, mtxs, res);
-        if (res.length === 0 || (limit != null && mtxs.length >= limit)) {
+        if (res.length === 0) {
+          break;
+        }
+        addFiltered(wex, tx, transactionsRequest, resultTransactions, res);
+        if (limit != null && resultTransactions.length >= limit) {
           break;
         }
         // Continue after last result
@@ -390,18 +404,6 @@ export async function getTransactionsV2(
         );
       }
     }
-
-    // Lookup full transactions
-    for (const mtx of mtxs) {
-      const ctx = await getContextForTransaction(wex, mtx.transactionId);
-      const txDetails = await ctx.lookupFullTransaction(tx);
-      // FIXME: This means that in some cases we can return fewer transactions
-      // than requested.
-      if (!txDetails) {
-        continue;
-      }
-      resultTransactions.push(txDetails);
-    }
   });
 
   sortTransactions(transactionsRequest, resultTransactions);

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]