Retrieving account transactions in parallel not serially

This commit is contained in:
dankito 2024-10-14 22:30:11 +02:00
parent 54ca55e2f9
commit e0e150e53a
1 changed files with 19 additions and 17 deletions

View File

@ -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" }
}
}