Use "transaction" to speed up group of queries

as this project is a template, this will help people understand how to run batch of queries.
This commit is contained in:
sonique6784 2021-06-29 23:11:09 +10:00 committed by GitHub
parent fee35c235d
commit 328bf185ba
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -47,9 +47,12 @@ class PeopleInSpaceRepository : KoinComponent {
// this is very basic implementation for now that removes all existing rows
// in db and then inserts results from api request
peopleInSpaceQueries?.deleteAll()
result.people.forEach {
peopleInSpaceQueries?.insertItem(it.name, it.craft)
// using "transaction" accelerate the batch of queries, especially inserting
peopleInSpaceQueries?.transaction {
peopleInSpaceQueries?.deleteAll()
result.people.forEach {
peopleInSpaceQueries?.insertItem(it.name, it.craft)
}
}
}