fix: bound provider storage retries
This commit is contained in:
@@ -32,9 +32,11 @@ class LoginViewModel @Inject constructor(
|
|||||||
private var usernameEdited = false
|
private var usernameEdited = false
|
||||||
private var rememberUsernameEdited = false
|
private var rememberUsernameEdited = false
|
||||||
private var autoLoginEdited = false
|
private var autoLoginEdited = false
|
||||||
|
private var loadedProfileId: com.flagship.abox.manager.domain.ProviderProfileId? = null
|
||||||
|
|
||||||
fun loadProfile(value: ProviderProfile) {
|
fun loadProfile(value: ProviderProfile) {
|
||||||
if (profile?.id == value.id &&
|
if (loadedProfileId == value.id ||
|
||||||
|
profile?.id == value.id &&
|
||||||
(loadingJob?.isActive == true || submitJob?.isActive == true)
|
(loadingJob?.isActive == true || submitJob?.isActive == true)
|
||||||
) return
|
) return
|
||||||
loadingJob?.cancel()
|
loadingJob?.cancel()
|
||||||
@@ -65,6 +67,7 @@ class LoginViewModel @Inject constructor(
|
|||||||
},
|
},
|
||||||
isLoadingPreferences = false,
|
isLoadingPreferences = false,
|
||||||
)
|
)
|
||||||
|
loadedProfileId = value.id
|
||||||
} catch (error: CancellationException) {
|
} catch (error: CancellationException) {
|
||||||
throw error
|
throw error
|
||||||
} catch (_: Exception) {
|
} catch (_: Exception) {
|
||||||
@@ -92,6 +95,7 @@ class LoginViewModel @Inject constructor(
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
profile = null
|
profile = null
|
||||||
|
loadedProfileId = null
|
||||||
usernameEdited = false
|
usernameEdited = false
|
||||||
rememberUsernameEdited = false
|
rememberUsernameEdited = false
|
||||||
autoLoginEdited = false
|
autoLoginEdited = false
|
||||||
|
|||||||
+4
-8
@@ -28,12 +28,9 @@ class ProviderProfileStoreImpl(
|
|||||||
private val safeData: Flow<Preferences>
|
private val safeData: Flow<Preferences>
|
||||||
get() = dataStore.data
|
get() = dataStore.data
|
||||||
.retryWhen { cause, attempt ->
|
.retryWhen { cause, attempt ->
|
||||||
if (cause !is IOException) return@retryWhen false
|
val retry = cause is IOException && attempt < MAX_READ_RETRIES
|
||||||
val delayMillis = (READ_RETRY_DELAY_MILLIS shl
|
if (retry) delay(READ_RETRY_DELAY_MILLIS)
|
||||||
attempt.coerceAtMost(MAX_BACKOFF_SHIFT).toInt())
|
retry
|
||||||
.coerceAtMost(MAX_READ_RETRY_DELAY_MILLIS)
|
|
||||||
delay(delayMillis)
|
|
||||||
true
|
|
||||||
}
|
}
|
||||||
.distinctUntilChanged()
|
.distinctUntilChanged()
|
||||||
|
|
||||||
@@ -118,9 +115,8 @@ class ProviderProfileStoreImpl(
|
|||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
private const val MAX_READ_RETRIES = 2L
|
||||||
private const val READ_RETRY_DELAY_MILLIS = 100L
|
private const val READ_RETRY_DELAY_MILLIS = 100L
|
||||||
private const val MAX_READ_RETRY_DELAY_MILLIS = 5_000L
|
|
||||||
private const val MAX_BACKOFF_SHIFT = 6L
|
|
||||||
private val PROFILE_IDS = stringSetPreferencesKey("profile_ids")
|
private val PROFILE_IDS = stringSetPreferencesKey("profile_ids")
|
||||||
private val ACTIVE_PROFILE_ID = stringPreferencesKey("active_profile_id")
|
private val ACTIVE_PROFILE_ID = stringPreferencesKey("active_profile_id")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user