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() { suspend fun updateAccountTransactions() {
val selectedAccount = uiState.transactionsFilter.value.selectedAccount withContext(Dispatchers.IOorDefault) {
if (selectedAccount != null) { val selectedAccount = uiState.transactionsFilter.value.selectedAccount
updateAccountTransactions(selectedAccount.bank, selectedAccount.bankAccount) if (selectedAccount != null) {
} else { updateAccountTransactions(selectedAccount.bank, selectedAccount.bankAccount)
getCurrentUiBanksList().forEach { bank -> } else {
// TODO: when implementing automatic account transactions update, filter out accounts with includeInAutomaticAccountsUpdate == false getCurrentUiBanksList().forEach { bank ->
updateAccountTransactions(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) { private suspend fun updateAccountTransactions(bank: BankAccessEntity, bankAccount: BankAccountEntity? = null) {
withContext(Dispatchers.IOorDefault) { try {
try { val response = client.updateAccountTransactionsAsync(bank, bankAccount?.let { listOf(it) })
val response = client.updateAccountTransactionsAsync(bank, bankAccount?.let { listOf(it) }) if (response.type == ResponseType.Success && response.data != null) {
if (response.type == ResponseType.Success && response.data != null) { handleSuccessfulUpdateAccountTransactionsResponse(bank, response.data!!)
handleSuccessfulUpdateAccountTransactionsResponse(bank, response.data!!) } else {
} else { handleUnsuccessfulBankingClientResponse(BankingClientAction.UpdateAccountTransactions, bankAccount?.displayName ?: bank.displayName, response)
handleUnsuccessfulBankingClientResponse(BankingClientAction.UpdateAccountTransactions, bankAccount?.displayName ?: bank.displayName, response)
}
} catch (e: Throwable) {
log.error(e) { "Could not update account transactions for $bank" }
} }
} catch (e: Throwable) {
log.error(e) { "Could not update account transactions for $bank" }
} }
} }