forked from upstream-mirrors/quik
Revert "Insert 1 conversation into realm at a time"
This reverts commit bb676e499e.
This commit is contained in:
@@ -26,19 +26,13 @@ class SyncManager(val context: Context, val contacts: ContactRepository) {
|
|||||||
.doOnNext {
|
.doOnNext {
|
||||||
// We need to set up realm on the io thread, and doOnSubscribe doesn't support setting a custom Scheduler
|
// We need to set up realm on the io thread, and doOnSubscribe doesn't support setting a custom Scheduler
|
||||||
realm = Realm.getDefaultInstance()
|
realm = Realm.getDefaultInstance()
|
||||||
realm?.executeTransaction {
|
realm?.beginTransaction()
|
||||||
it.delete(Conversation::class.java)
|
realm?.deleteAll()
|
||||||
it.delete(Message::class.java)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
.flatMap { cursor -> cursor.asFlowable() }
|
.flatMap { cursor -> cursor.asFlowable() }
|
||||||
.map { cursor -> Conversation(cursor, contacts) }
|
.map { cursor -> Conversation(cursor, contacts) }
|
||||||
.distinct { conversation -> conversation.id }
|
.distinct { conversation -> conversation.id }
|
||||||
.doOnNext { conversation ->
|
.doOnNext { conversation -> realm?.insertOrUpdate(conversation) }
|
||||||
realm?.beginTransaction()
|
|
||||||
realm?.insertOrUpdate(conversation)
|
|
||||||
}
|
|
||||||
.doAfterNext { realm?.commitTransaction() }
|
|
||||||
.map { conversation -> conversation.id }
|
.map { conversation -> conversation.id }
|
||||||
.concatMap { threadId ->
|
.concatMap { threadId ->
|
||||||
val uri = Uri.withAppendedPath(MessageColumns.URI, threadId.toString())
|
val uri = Uri.withAppendedPath(MessageColumns.URI, threadId.toString())
|
||||||
@@ -51,9 +45,14 @@ class SyncManager(val context: Context, val contacts: ContactRepository) {
|
|||||||
.doOnNext { message -> realm?.insertOrUpdate(message) }
|
.doOnNext { message -> realm?.insertOrUpdate(message) }
|
||||||
.count()
|
.count()
|
||||||
.toFlowable()
|
.toFlowable()
|
||||||
.doOnNext { realm?.close() }
|
.doOnNext {
|
||||||
|
realm?.commitTransaction()
|
||||||
|
realm?.close()
|
||||||
|
}
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
.subscribe { completionListener.invoke() }
|
.subscribe({
|
||||||
|
completionListener.invoke()
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user