mirror of
https://github.com/tapframe/NuvioStreaming.git
synced 2026-08-17 21:05:43 +00:00
fix: skip redundant Trakt watched refresh (NUVIO-MOBILE-Q3)
This commit is contained in:
parent
15fcb8d25e
commit
7a491570af
2 changed files with 29 additions and 1 deletions
|
|
@ -113,6 +113,11 @@ internal suspend fun <T> watchedProviderRefreshOrNull(
|
|||
null
|
||||
}
|
||||
|
||||
internal fun extraWatchedKeysChanged(
|
||||
previous: Set<String>?,
|
||||
current: Set<String>,
|
||||
): Boolean = previous.orEmpty() != current
|
||||
|
||||
object WatchedRepository {
|
||||
private data class WatchedRefreshOperation(
|
||||
val profileId: Int,
|
||||
|
|
@ -1099,7 +1104,10 @@ object WatchedRepository {
|
|||
adapter.observeExtraWatchedKeys(currentProfileId)
|
||||
.distinctUntilChanged()
|
||||
.collectLatest { extraKeys ->
|
||||
val keysChanged = providerExtraWatchedKeys[providerId] != extraKeys
|
||||
val keysChanged = extraWatchedKeysChanged(
|
||||
previous = providerExtraWatchedKeys[providerId],
|
||||
current = extraKeys,
|
||||
)
|
||||
if (keysChanged) {
|
||||
val freshItems = watchedProviderRefreshOrNull(
|
||||
refresh = {
|
||||
|
|
|
|||
|
|
@ -14,6 +14,26 @@ import kotlin.test.assertNull
|
|||
import kotlin.test.assertTrue
|
||||
|
||||
class WatchedRepositoryTest {
|
||||
@Test
|
||||
fun emptyProviderExtraKeys_doNotTriggerInitialRefresh() {
|
||||
assertFalse(extraWatchedKeysChanged(previous = null, current = emptySet()))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun populatedProviderExtraKeys_triggerRefreshFromEmptyState() {
|
||||
assertTrue(extraWatchedKeysChanged(previous = null, current = setOf("series:tt1:-1:-1")))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun changedProviderExtraKeys_triggerRefresh() {
|
||||
assertTrue(
|
||||
extraWatchedKeysChanged(
|
||||
previous = setOf("series:tt1:-1:-1"),
|
||||
current = setOf("series:tt2:-1:-1"),
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun providerRefreshFailure_isContainedWithoutReplacingState() = runBlocking {
|
||||
val failure = IllegalStateException("rate limited")
|
||||
|
|
|
|||
Loading…
Reference in a new issue