Updated on 2026-08-14
This commit is contained in:
parent
592351f421
commit
104d60aebd
1 changed files with 8 additions and 4 deletions
|
|
@ -46,7 +46,7 @@ internal class DefaultQuotesRepository(
|
|||
fetchExpiredQuotes(
|
||||
currenciesIds = currenciesIds,
|
||||
appCurrencyId = appCurrency.id,
|
||||
refresh = true,
|
||||
refresh = false,
|
||||
)
|
||||
|
||||
quotesStore.get(currenciesIds)
|
||||
|
|
@ -120,6 +120,7 @@ internal class DefaultQuotesRepository(
|
|||
|
||||
val expiredCurrenciesIds = filterExpiredCurrenciesIds(
|
||||
currenciesIds = currenciesIds,
|
||||
appCurrencyId = appCurrencyId,
|
||||
refresh = refresh || quotesFetchedForAppCurrency != appCurrencyId,
|
||||
)
|
||||
if (expiredCurrenciesIds.isEmpty()) return
|
||||
|
|
@ -150,7 +151,7 @@ internal class DefaultQuotesRepository(
|
|||
onError = { error ->
|
||||
Timber.e(error)
|
||||
|
||||
cacheRegistry.invalidate(rawCurrenciesIds.map { getQuoteCacheKey(it) })
|
||||
cacheRegistry.invalidate(rawCurrenciesIds.map { getQuoteCacheKey(it, appCurrencyId) })
|
||||
quotesStore.storeEmptyQuotes(currenciesIds = rawCurrenciesIds)
|
||||
},
|
||||
)
|
||||
|
|
@ -158,12 +159,13 @@ internal class DefaultQuotesRepository(
|
|||
|
||||
private suspend fun filterExpiredCurrenciesIds(
|
||||
currenciesIds: Set<CryptoCurrency.RawID>,
|
||||
appCurrencyId: String,
|
||||
refresh: Boolean,
|
||||
): Set<CryptoCurrency.RawID> {
|
||||
return currenciesIds.fold(hashSetOf()) { acc, currencyId ->
|
||||
if (currencyId !in acc) {
|
||||
cacheRegistry.invokeOnExpire(
|
||||
key = getQuoteCacheKey(currencyId),
|
||||
key = getQuoteCacheKey(currencyId, appCurrencyId),
|
||||
skipCache = refresh,
|
||||
block = { acc.add(currencyId) },
|
||||
)
|
||||
|
|
@ -172,5 +174,7 @@ internal class DefaultQuotesRepository(
|
|||
}
|
||||
}
|
||||
|
||||
private fun getQuoteCacheKey(rawCurrencyId: CryptoCurrency.RawID): String = "quote_${rawCurrencyId.value}"
|
||||
private fun getQuoteCacheKey(rawCurrencyId: CryptoCurrency.RawID, appCurrencyId: String): String {
|
||||
return "quote_${rawCurrencyId.value}_$appCurrencyId"
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue