Android room database - LiveData paging slow appear when a lot of insert/update into database
I'm working in a project realtime with LiveData and Paging database I meet the issue: -- My list take long time to appear when have a lot of insert/update to database.
val viewModel = ViewModelProviders.of(this).get(MyViewModel::class.java)
viewModel.init(database)
viewModel.getUserList()?.observe(this, Observer {
println("load paging :::: ${it?.size}")
})
could anybody help me
Thank you so much. Hieu Tran
why you close this? have any solution?
currently, I don't have any solution :)
I use LiveData to my project without room, I find when I change database the ui update very slow. It's there a good way to solve this? to update sql or about ui code? Thanks
maybe, you load large database to UI? I also meet this issue when I got database realtime (same as chat realtime)
I can confirm it, i tried using Room with Livedata and the changes is quite slow.
Do you have any solution for this?
Same problem use Room when large data
I think that Room (+LiveData) will re-query for every updates so it's causing slow when have a lot of insert/update
@NhatPham94 I know, but how to fix it :D
@tvhieuit Currently I'm working on a demo with Paging lib + Room + LiveData, I trigger updates and try to debug and see what's going on. The result is Room only loads specific number of items follow what I've config with Paging lib (ex : page size) instead of re-create the whole query
@tvhieuit Have you found any solutions ?
Currently, the Paging library will start loading from the DB, and if content in the DB has changed by the time it's done, we won't send the result, and will instead reload.
The behavior is intended to avoid sending too many, too-similar lists to the UI, but we could make it smarter to avoid the problem (send something to avoid spinning continuously). If you file a bug ( https://issuetracker.google.com/issues/new?component=413106&template=1096385 ), I can look into it, especially if you have a sample repro project.
Hi , Anybody found resolutions for this issue.
Related issue with a possible solution: https://issuetracker.google.com/issues/134685570
Hope you have fired query in doAsync{} !!
@sidthakkar12 paging is by definition async, so maybe you don't understand this issue.
I use this https://realm.io/blog/realm-java-0-84-0/ to insert many data, I was try insert data up to 2Mb and no take long time.
but it take so many size of stored to save that data.
I try this code on room and get better time to insert many data
@Dao
interface Dao{
@Insert(onConflict = REPLACE)
fun insertData(m :List
I experienced the same issue and i found that i have two updates, one after another, on the same table. The first update was triggering the observer but the changes were not relevant for the query and no results were returned, the second update wasn't triggering the observer immediately because it was busy querying the data after changes from the first update and the event has been postponed. Merging to updates into one query has fixed the issue (if it is not possible you may try using @Transcation )
As Chris mentioned - this seems to be working as intended.
In v3 APIs, we have an open-issue to better support the high frequency updates use-case by allowing a stream-based API for delivering item / page updates without invalidation loop: https://issuetracker.google.com/149482600
Please follow / comment / +1 there!