mirror of
https://github.com/ouchadam/small-talk.git
synced 2025-02-16 20:20:59 +01:00
using a single sync flow instance to reduce memory and risk of concurrent flows
This commit is contained in:
parent
894592870b
commit
1c37667485
@ -8,7 +8,6 @@ import app.dapk.st.matrix.sync.internal.SideEffectFlowIterator
|
|||||||
import app.dapk.st.matrix.sync.internal.overview.ReducedSyncFilterUseCase
|
import app.dapk.st.matrix.sync.internal.overview.ReducedSyncFilterUseCase
|
||||||
import app.dapk.st.matrix.sync.internal.request.syncRequest
|
import app.dapk.st.matrix.sync.internal.request.syncRequest
|
||||||
import app.dapk.st.matrix.sync.internal.room.SyncSideEffects
|
import app.dapk.st.matrix.sync.internal.room.SyncSideEffects
|
||||||
import kotlinx.coroutines.flow.Flow
|
|
||||||
import kotlinx.coroutines.flow.cancellable
|
import kotlinx.coroutines.flow.cancellable
|
||||||
import kotlinx.coroutines.flow.flow
|
import kotlinx.coroutines.flow.flow
|
||||||
|
|
||||||
@ -25,8 +24,7 @@ internal class SyncUseCase(
|
|||||||
private val syncConfig: SyncConfig,
|
private val syncConfig: SyncConfig,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
fun sync(): Flow<Unit> {
|
private val _flow = flow {
|
||||||
return flow {
|
|
||||||
val credentials = credentialsStore.credentials()!!
|
val credentials = credentialsStore.credentials()!!
|
||||||
val filterId = filterUseCase.reducedFilter(credentials.userId)
|
val filterId = filterUseCase.reducedFilter(credentials.userId)
|
||||||
with(flowIterator) {
|
with(flowIterator) {
|
||||||
@ -37,7 +35,6 @@ internal class SyncUseCase(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
}.cancellable()
|
}.cancellable()
|
||||||
}
|
|
||||||
|
|
||||||
private suspend fun onEachSyncIteration(filterId: SyncService.FilterId, credentials: UserCredentials, previousState: OverviewState?): OverviewState? {
|
private suspend fun onEachSyncIteration(filterId: SyncService.FilterId, credentials: UserCredentials, previousState: OverviewState?): OverviewState? {
|
||||||
val syncToken = syncStore.read(key = SyncStore.SyncKey.Overview)
|
val syncToken = syncStore.read(key = SyncStore.SyncKey.Overview)
|
||||||
@ -85,4 +82,6 @@ internal class SyncUseCase(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun sync() = _flow
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user