Make bookkeeper optional (#529)
Signed-off-by: Ajesh <ajesh_nair@ymail.com> Co-authored-by: Ajesh <aj@Ajeshs-MacBook-Pro.local>
This commit is contained in:
parent
99e7f2bd93
commit
e6786d20dc
4 changed files with 8 additions and 8 deletions
|
@ -27,7 +27,7 @@ interface StoreBuilder<Key : Any, Network : Any, Output : Any, Local : Any> {
|
|||
|
||||
fun <Response : Any> build(
|
||||
updater: Updater<Key, Output, Response>,
|
||||
bookkeeper: Bookkeeper<Key>
|
||||
bookkeeper: Bookkeeper<Key>? = null
|
||||
): MutableStore<Key, Output>
|
||||
|
||||
/**
|
||||
|
|
|
@ -30,7 +30,7 @@ import org.mobilenativefoundation.store.store5.internal.result.EagerConflictReso
|
|||
internal class RealMutableStore<Key : Any, Network : Any, Output : Any, Local : Any>(
|
||||
private val delegate: RealStore<Key, Network, Output, Local>,
|
||||
private val updater: Updater<Key, Output, *>,
|
||||
private val bookkeeper: Bookkeeper<Key>,
|
||||
private val bookkeeper: Bookkeeper<Key>?,
|
||||
) : MutableStore<Key, Output>, Clear.Key<Key> by delegate, Clear.All by delegate {
|
||||
|
||||
private val storeLock = Mutex()
|
||||
|
@ -107,9 +107,9 @@ internal class RealMutableStore<Key : Any, Network : Any, Output : Any, Local :
|
|||
created = request.created,
|
||||
updaterResult = updaterResult
|
||||
)
|
||||
bookkeeper.clear(request.key)
|
||||
bookkeeper?.clear(request.key)
|
||||
} else {
|
||||
bookkeeper.setLastFailedSync(request.key)
|
||||
bookkeeper?.setLastFailedSync(request.key)
|
||||
}
|
||||
|
||||
return updaterResult
|
||||
|
@ -199,7 +199,7 @@ internal class RealMutableStore<Key : Any, Network : Any, Output : Any, Local :
|
|||
}
|
||||
|
||||
private suspend fun conflictsMightExist(key: Key): Boolean {
|
||||
val lastFailedSync = bookkeeper.getLastFailedSync(key)
|
||||
val lastFailedSync = bookkeeper?.getLastFailedSync(key)
|
||||
return lastFailedSync != null || writeRequestsQueueIsEmpty(key).not()
|
||||
}
|
||||
|
||||
|
@ -215,7 +215,7 @@ internal class RealMutableStore<Key : Any, Network : Any, Output : Any, Local :
|
|||
withThreadSafety(key) {
|
||||
val latest = delegate.latestOrNull(key)
|
||||
when {
|
||||
latest == null || conflictsMightExist(key).not() -> EagerConflictResolutionResult.Success.NoConflicts
|
||||
latest == null || bookkeeper == null || conflictsMightExist(key).not() -> EagerConflictResolutionResult.Success.NoConflicts
|
||||
else -> {
|
||||
try {
|
||||
val updaterResult = updater.post(key, latest).also { updaterResult ->
|
||||
|
|
|
@ -70,7 +70,7 @@ internal class RealStoreBuilder<Key : Any, Network : Any, Output : Any, Local :
|
|||
|
||||
override fun <UpdaterResult : Any> build(
|
||||
updater: Updater<Key, Output, UpdaterResult>,
|
||||
bookkeeper: Bookkeeper<Key>
|
||||
bookkeeper: Bookkeeper<Key>?
|
||||
): MutableStore<Key, Output> =
|
||||
build().asMutableStore<Key, Network, Output, Local, UpdaterResult>(
|
||||
updater = updater,
|
||||
|
|
|
@ -38,7 +38,7 @@ suspend fun <Key : Any, Output : Any> Store<Key, Output>.fresh(key: Key) =
|
|||
@Suppress("UNCHECKED_CAST")
|
||||
fun <Key : Any, Network : Any, Output : Any, Local : Any, Response : Any> Store<Key, Output>.asMutableStore(
|
||||
updater: Updater<Key, Output, Response>,
|
||||
bookkeeper: Bookkeeper<Key>
|
||||
bookkeeper: Bookkeeper<Key>?
|
||||
): MutableStore<Key, Output> {
|
||||
val delegate = this as? RealStore<Key, Network, Output, Local>
|
||||
?: throw Exception("MutableStore requires Store to be built using StoreBuilder")
|
||||
|
|
Loading…
Reference in a new issue