Room : LiveData from Dao will trigger Observer.onChanged on every Update, even if the LiveData value has no change

前端 未结 5 1373
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-05 10:14

I found that the LiveData returned by Dao will call its observer whenever the row is updated in DB, even if the LiveData value is obviously not changed.

Consider a s

5条回答
  •  广开言路
    2020-12-05 10:58

    Currently there is no way to stop triggering Observer.onChanged which is why I think the LiveData will be useless for most of the queries that are using some joins. Like @Pinakin mentioned there is a MediatorLiveData but this is just a filter and the data still gets loaded on every change. Imagine having 3 left joins in 1 query where you only need a field or two from those joins. In case you implement PagedList every time any record from those 4 tables (main + 3 joined tables) gets updated, the query will be called again. This is OK for some some tables with small amount of data, but correct me if I wrong this would be bad in case of bigger tables. It would be best if we would have some way of setting the query to be refreshed only if the main table is updated or ideally to have a way to refresh only if fields from that query are updated in the database.

提交回复
热议问题