fix: bound provider storage retries

This commit is contained in:
2026-08-24 02:31:59 +08:00
parent cf2c59a493
commit d0ad601efc
2 changed files with 9 additions and 9 deletions
@@ -32,9 +32,11 @@ class LoginViewModel @Inject constructor(
private var usernameEdited = false
private var rememberUsernameEdited = false
private var autoLoginEdited = false
private var loadedProfileId: com.flagship.abox.manager.domain.ProviderProfileId? = null
fun loadProfile(value: ProviderProfile) {
if (profile?.id == value.id &&
if (loadedProfileId == value.id ||
profile?.id == value.id &&
(loadingJob?.isActive == true || submitJob?.isActive == true)
) return
loadingJob?.cancel()
@@ -65,6 +67,7 @@ class LoginViewModel @Inject constructor(
},
isLoadingPreferences = false,
)
loadedProfileId = value.id
} catch (error: CancellationException) {
throw error
} catch (_: Exception) {
@@ -92,6 +95,7 @@ class LoginViewModel @Inject constructor(
return
}
profile = null
loadedProfileId = null
usernameEdited = false
rememberUsernameEdited = false
autoLoginEdited = false
@@ -28,12 +28,9 @@ class ProviderProfileStoreImpl(
private val safeData: Flow<Preferences>
get() = dataStore.data
.retryWhen { cause, attempt ->
if (cause !is IOException) return@retryWhen false
val delayMillis = (READ_RETRY_DELAY_MILLIS shl
attempt.coerceAtMost(MAX_BACKOFF_SHIFT).toInt())
.coerceAtMost(MAX_READ_RETRY_DELAY_MILLIS)
delay(delayMillis)
true
val retry = cause is IOException && attempt < MAX_READ_RETRIES
if (retry) delay(READ_RETRY_DELAY_MILLIS)
retry
}
.distinctUntilChanged()
@@ -118,9 +115,8 @@ class ProviderProfileStoreImpl(
}
companion object {
private const val MAX_READ_RETRIES = 2L
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 ACTIVE_PROFILE_ID = stringPreferencesKey("active_profile_id")