Skip to content

StreamVault is a TV-first free IPTV player for Android TV built with Kotlin, Jetpack Compose, Room, Hilt, and Media3.

Fix Xtream partial live sync commit

David Nashash8a6b9d99abd6
diff --git a/data/src/main/java/com/streamvault/data/sync/SyncManager.kt b/data/src/main/java/com/streamvault/data/sync/SyncManager.kt
index 60954aad..dbb46a50 100644
--- a/data/src/main/java/com/streamvault/data/sync/SyncManager.kt
+++ b/data/src/main/java/com/streamvault/data/sync/SyncManager.kt
@@ -3125,17 +3125,34 @@ class SyncManager @Inject constructor(
}
}
is CatalogStrategyResult.Partial -> {
- val liveCatalog = mergeVisibleLiveSyncWithHiddenStoredContent(
- providerId = providerId,
- visibleCategories = liveSyncResult.categories,
- visibleChannels = liveResult.items.map { it.toEntity() },
- hiddenLiveCategoryIds = hiddenLiveCategoryIds
- )
- syncCatalogStore.upsertLiveCatalog(
- providerId = providerId,
- categories = liveCatalog.categories,
- channels = liveCatalog.channels
- )
+ liveSyncResult.stagedSessionId?.let { sessionId ->
+ val mergedCategories = mergeVisibleLiveCategoriesWithHiddenStoredContent(
+ providerId = providerId,
+ visibleCategories = liveSyncResult.categories,
+ hiddenLiveCategoryIds = hiddenLiveCategoryIds
+ )
+ if (hiddenLiveCategoryIds.isNotEmpty()) {
+ mergeHiddenChannelsIntoStaging(providerId, sessionId, hiddenLiveCategoryIds)
+ }
+ syncCatalogStore.applyStagedLiveCatalogUpsertOnly(
+ providerId = providerId,
+ sessionId = sessionId,
+ categories = mergedCategories
+ )
+ liveSyncResult.stagedAcceptedCount
+ } ?: run {
+ val liveCatalog = mergeVisibleLiveSyncWithHiddenStoredContent(
+ providerId = providerId,
+ visibleCategories = liveSyncResult.categories,
+ visibleChannels = liveResult.items.map { it.toEntity() },
+ hiddenLiveCategoryIds = hiddenLiveCategoryIds
+ )
+ syncCatalogStore.upsertLiveCatalog(
+ providerId = providerId,
+ categories = liveCatalog.categories,
+ channels = liveCatalog.channels
+ )
+ }
}
is CatalogStrategyResult.EmptyValid,
is CatalogStrategyResult.Failure -> {
diff --git a/data/src/test/java/com/streamvault/data/sync/SyncManagerTest.kt b/data/src/test/java/com/streamvault/data/sync/SyncManagerTest.kt
index e3ca4905..678b420b 100644
--- a/data/src/test/java/com/streamvault/data/sync/SyncManagerTest.kt
+++ b/data/src/test/java/com/streamvault/data/sync/SyncManagerTest.kt
@@ -889,6 +889,52 @@ class SyncManagerTest {
assertThat(mgr.currentSyncState(1L)).isInstanceOf(SyncState.Error::class.java)
}
+ @Test
+ fun `sync_xtream_partial_live_category_bulk_commits_staged_channels`() = runTest {
+ val mgr = buildManager(providerType = ProviderType.XTREAM_CODES)
+ xtreamBackend.respond(
+ action = "get_live_categories",
+ body = """
+ [
+ {"category_id":"1","category_name":"News"},
+ {"category_id":"2","category_name":"Sports"}
+ ]
+ """.trimIndent()
+ )
+ xtreamBackend.respond(
+ action = "get_live_streams",
+ body = """
+ [
+ {
+ "name": "Channel One",
+ "stream_id": 1001,
+ "category_id": "1",
+ "stream_icon": "https://example.com/ch1.png",
+ "tv_archive": 0,
+ "num": 1
+ }
+ ]
+ """.trimIndent()
+ )
+ xtreamBackend.respond(
+ action = "get_live_streams",
+ body = "{" + '"' + "error" + '"' + ":" + '"' + "category unavailable" + '"' + "}",
+ code = 500
+ )
+ stubXtreamEmptyVodAndSeriesCategories()
+
+ val result = mgr.sync(1L, force = false)
+ advanceUntilIdle()
+
+ assertThat(result.isSuccess).isTrue()
+ assertThat(mgr.currentSyncState(1L)).isInstanceOf(SyncState.Partial::class.java)
+ assertThat(syncMetadataRepo.getMetadata(1L)?.liveCount).isEqualTo(1)
+ val stagedSessionId = argumentCaptor<Long>()
+ verify(catalogSyncDao).updateChangedChannelsFromStage(eq(1L), stagedSessionId.capture())
+ verify(catalogSyncDao).insertMissingChannelsFromStage(1L, stagedSessionId.firstValue)
+ verify(catalogSyncDao).clearChannelStages(1L, stagedSessionId.firstValue)
+ }
+
@Test
fun `sync_xtream_vod_category_failure_does_not_fetch_movie_streams`() = runTest {
val mgr = buildManager(providerType = ProviderType.XTREAM_CODES)
diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md
index 1532dcad..6c1dbf97 100644
--- a/docs/CHANGELOG.md
+++ b/docs/CHANGELOG.md
@@ -42,6 +42,7 @@ All notable product changes are recorded in this document.
- Fixed missing favorite actions on series detail screens.
- Fixed Xtream series detail pages rendering empty when only metadata-only season payloads were returned.
- Fixed Xtream live sync category requests hanging near the end of large imports.
+- Fixed Xtream live category-bulk partial sync dropping staged channels and leaving providers stuck on `Live 0`/inactive after successful live category imports.
- Fixed VOD category ordering to sort by provider-added time.
- Fixed Stalker VOD category filtering drifting when portal responses omitted category metadata.
- Fixed backup export and import to preserve hidden live categories and channels.