From e0e150e53abd572129decaec58d2cab05da0a30b Mon Sep 17 00:00:00 2001 From: dankito Date: Mon, 14 Oct 2024 22:30:11 +0200 Subject: [PATCH] Retrieving account transactions in parallel not serially --- .../banking/ui/service/BankingService.kt | 36 ++++++++++--------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/service/BankingService.kt b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/service/BankingService.kt index c33211d..9186580 100644 --- a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/service/BankingService.kt +++ b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/service/BankingService.kt @@ -207,29 +207,31 @@ class BankingService( suspend fun updateAccountTransactions() { - val selectedAccount = uiState.transactionsFilter.value.selectedAccount - if (selectedAccount != null) { - updateAccountTransactions(selectedAccount.bank, selectedAccount.bankAccount) - } else { - getCurrentUiBanksList().forEach { bank -> - // TODO: when implementing automatic account transactions update, filter out accounts with includeInAutomaticAccountsUpdate == false - updateAccountTransactions(bank) + withContext(Dispatchers.IOorDefault) { + val selectedAccount = uiState.transactionsFilter.value.selectedAccount + if (selectedAccount != null) { + updateAccountTransactions(selectedAccount.bank, selectedAccount.bankAccount) + } else { + getCurrentUiBanksList().forEach { bank -> + launch { + // TODO: when implementing automatic account transactions update, filter out accounts with includeInAutomaticAccountsUpdate == false + updateAccountTransactions(bank) + } + } } } } private suspend fun updateAccountTransactions(bank: BankAccessEntity, bankAccount: BankAccountEntity? = null) { - withContext(Dispatchers.IOorDefault) { - try { - val response = client.updateAccountTransactionsAsync(bank, bankAccount?.let { listOf(it) }) - if (response.type == ResponseType.Success && response.data != null) { - handleSuccessfulUpdateAccountTransactionsResponse(bank, response.data!!) - } else { - handleUnsuccessfulBankingClientResponse(BankingClientAction.UpdateAccountTransactions, bankAccount?.displayName ?: bank.displayName, response) - } - } catch (e: Throwable) { - log.error(e) { "Could not update account transactions for $bank" } + try { + val response = client.updateAccountTransactionsAsync(bank, bankAccount?.let { listOf(it) }) + if (response.type == ResponseType.Success && response.data != null) { + handleSuccessfulUpdateAccountTransactionsResponse(bank, response.data!!) + } else { + handleUnsuccessfulBankingClientResponse(BankingClientAction.UpdateAccountTransactions, bankAccount?.displayName ?: bank.displayName, response) } + } catch (e: Throwable) { + log.error(e) { "Could not update account transactions for $bank" } } }