Updated on 2026-08-14
This commit is contained in:
parent
85b000a850
commit
a0ef13e0cf
12 changed files with 278 additions and 60 deletions
|
|
@ -46,14 +46,6 @@ internal class DefaultNetworksStatusesStore(
|
|||
|
||||
if (cachedStatuses.isNotEmpty()) {
|
||||
send(cachedStatuses)
|
||||
|
||||
/**
|
||||
* Required for storing cache data.
|
||||
* This will help to recognize networks that are still uploaded.
|
||||
*
|
||||
* @see mergeStatuses
|
||||
*/
|
||||
storeAll(key = key, values = cachedStatuses)
|
||||
}
|
||||
|
||||
runtimeDataStore.get(provideStringKey(key))
|
||||
|
|
@ -118,8 +110,18 @@ internal class DefaultNetworksStatusesStore(
|
|||
return networks.mapNotNullTo(hashSetOf()) { network ->
|
||||
val runtimeStatus = runtimeStatuses.firstOrNull { it.network == network }
|
||||
|
||||
if (runtimeStatus == null || runtimeStatus.value is NetworkStatus.Unreachable) {
|
||||
getCachedStatusIfPossible(cachedStatuses = cachedStatuses, network = network)
|
||||
if (runtimeStatus == null) {
|
||||
getCachedStatusIfPossible(
|
||||
cachedStatuses = cachedStatuses,
|
||||
network = network,
|
||||
source = StatusSource.CACHE,
|
||||
)
|
||||
} else if (runtimeStatus.value is NetworkStatus.Unreachable) {
|
||||
getCachedStatusIfPossible(
|
||||
cachedStatuses = cachedStatuses,
|
||||
network = network,
|
||||
source = StatusSource.ONLY_CACHE,
|
||||
)
|
||||
?: runtimeStatus
|
||||
} else {
|
||||
runtimeStatus
|
||||
|
|
@ -127,12 +129,16 @@ internal class DefaultNetworksStatusesStore(
|
|||
}
|
||||
}
|
||||
|
||||
private fun getCachedStatusIfPossible(cachedStatuses: Set<NetworkStatus>, network: Network): NetworkStatus? {
|
||||
private fun getCachedStatusIfPossible(
|
||||
cachedStatuses: Set<NetworkStatus>,
|
||||
network: Network,
|
||||
source: StatusSource,
|
||||
): NetworkStatus? {
|
||||
val cached = cachedStatuses.firstOrNull { it.network == network } ?: return null
|
||||
|
||||
val updatedCachedStatus = when (val status = cached.value) {
|
||||
is NetworkStatus.NoAccount -> status.copy(source = StatusSource.ONLY_CACHE)
|
||||
is NetworkStatus.Verified -> status.copy(source = StatusSource.ONLY_CACHE)
|
||||
is NetworkStatus.NoAccount -> status.copy(source = source)
|
||||
is NetworkStatus.Verified -> status.copy(source = source)
|
||||
is NetworkStatus.Unreachable,
|
||||
is NetworkStatus.MissedDerivation,
|
||||
-> null
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue