Search posts, tags, users, and pages
Tushar Pingale
Make dreams happen
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...
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) }
This is because we are unaware of the list size. The list is populated based on paginated response.
Siddhesh Redkar
Software Engineer (iOS)
๐๐ป Great job
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) }