taler-android

Android apps for GNU Taler (wallet, PoS, cashier)
Log | Files | Refs | README | LICENSE

delete-transaction-requeries-deleted-id.diff (3400B)


      1 diff --git a/wallet/src/main/java/net/taler/wallet/transactions/TransactionManager.kt b/wallet/src/main/java/net/taler/wallet/transactions/TransactionManager.kt
      2 index d7e95ce6..d6ed35d4 100644
      3 --- a/wallet/src/main/java/net/taler/wallet/transactions/TransactionManager.kt
      4 +++ b/wallet/src/main/java/net/taler/wallet/transactions/TransactionManager.kt
      5 @@ -37,6 +37,9 @@ import net.taler.wallet.balances.ScopeInfo
      6  import net.taler.wallet.transactions.TransactionAction.Delete
      7  import org.json.JSONObject
      8  
      9 +/** How many deleted transaction ids to remember, to recognise their transitions. */
     10 +private const val DELETED_IDS_REMEMBERED = 32
     11 +
     12  sealed class TransactionsResult {
     13      data object None : TransactionsResult()
     14      data class Error(val error: TalerErrorInfo) : TransactionsResult()
     15 @@ -93,6 +96,30 @@ class TransactionManager(
     16      val selectedTransaction = mSelectedTransaction.asStateFlow()
     17      val selectedTransferOption = mSelectedTransferOption.asStateFlow()
     18  
     19 +    /**
     20 +     * Ids this wallet has deleted, so their transition notifications can be
     21 +     * ignored.
     22 +     *
     23 +     * Deleting a transaction makes wallet-core emit transitions for it, and
     24 +     * [onTransactionStateTransition] asks for the transaction before it can
     25 +     * know what the transition was -- which after a deletion is a request for
     26 +     * something that no longer exists: 7052, logged at error level, three
     27 +     * times per deletion.  An id never comes back, so a bounded set is enough.
     28 +     */
     29 +    private val deletedIds = LinkedHashSet<String>()
     30 +
     31 +    @Synchronized
     32 +    private fun rememberDeleted(transactionId: String) {
     33 +        deletedIds.add(transactionId)
     34 +        while (deletedIds.size > DELETED_IDS_REMEMBERED) {
     35 +            val oldest = deletedIds.first()
     36 +            deletedIds.remove(oldest)
     37 +        }
     38 +    }
     39 +
     40 +    @Synchronized
     41 +    private fun wasDeleted(transactionId: String) = transactionId in deletedIds
     42 +
     43      /**
     44       * Streams the [RECENT_LIMIT] most recent transactions for [scopeInfo], as
     45       * shown on the balances screen.
     46 @@ -168,6 +195,9 @@ class TransactionManager(
     47       * not been requested yet are left untouched.
     48       */
     49      fun onTransactionStateTransition(transactionId: String) = scope.launch {
     50 +        // Nothing to refresh and no scope to reload for a transaction we
     51 +        // deleted; asking is what filled the log with 7052 errors.
     52 +        if (wasDeleted(transactionId)) return@launch
     53          val transaction = getTransactionById(transactionId)
     54  
     55          if (transaction != null && mSelectedTransactionId.value == transactionId) {
     56 @@ -282,6 +312,7 @@ class TransactionManager(
     57  
     58      fun deleteTransaction(transactionId: String, onError: (it: TalerErrorInfo) -> Unit) =
     59          scope.launch {
     60 +            rememberDeleted(transactionId)
     61              api.request<Unit>("deleteTransaction") {
     62                  put("transactionId", transactionId)
     63              }.onError {
     64 @@ -357,6 +388,7 @@ class TransactionManager(
     65              fullTransactions.values.flatten().filter { transaction ->
     66                  transaction.transactionId in transactionIds && Delete in transaction.txActions
     67              }.forEach { toBeDeletedTx ->
     68 +                rememberDeleted(toBeDeletedTx.transactionId)
     69                  api.request<Unit>("deleteTransaction") {
     70                      put("transactionId", toBeDeletedTx.transactionId)
     71                  }.onError {