https://kotlinlang.org logo
#exposed
Title
# exposed
h

Hakon Grotte

10/23/2023, 7:33 AM
I have a question regarding concurrent update operations using
suspendedTransactionAsync
. I feel like this is a bad idea, but I'm not completely sure why. Given the definitions:
Copy code
data class CustomerTransactionId (
    val customerId: UUID,
    val transactionId: UUID
)
val customerTransactionIds: List<CustomerTransactionId>
Is the following code a bad idea? Why?
Copy code
customerTransactionIds.map { customerTransactionId ->
            suspendedTransactionAsync(Dispatchers.IO) {
                CustomerTransactionTable.update({                                            CustomerTransactionTable.customerId eq customerTransactionId.customerId                           
                }) { updateStmt ->
                    updateStmt[transactionId] = customerTransactionId.transactionId
                }
            }
        }.awaitAll()
Each update statement is independent of the others.
The size of the input list will usually be within the range 1-10. Moreover, the application uses HikariCP - so the concurrency might be constrained at some level from that