Leveraging fold operator in Kotlin flow to optimize Room DB upserts
Hey everyone, today we will look into an interesting topic to optimize room DB upserts using fold in Kotlin flow.
The case?
We are working on a chat application where we fetch a list of chats in pages from the network and upsert it into DB as it is a...
tusharpingale.hashnode.dev6 min read
Ilya
Why wouldn't you just use subList? db.chatDao().insertChats(list.subList(0, 45))
if (list.size > 45) list.subList(45, list.size).chunked(150).forEach { db.chatDao().insertChats(it) }