Wait for switched user's home settings before fetching data (#1981)
## Description There is a race condition when switching users between `HomeViewModel.init` and `HomeSetttingsService.loadCurrentSettings`. This happens more often if the new user doesn't have a customized home page. The result is that the previous user's home page settings are used for the initial load of the home page. This PR fixes this by collecting the flows for current user & home settings, waiting until both are valid and refer to the same user, then fetch the data. ### Related issues Fixes #1976 Maybe related (and fixes) #1980, but need to investigate more ### Testing Emulator. It's easy to reproduce by adding a manual `delay(2.seconds)` at the start of `HomeSetttingsService.loadCurrentSettings`. ## Screenshots N/A ## AI or LLM usage None
This commit is contained in:
parent
ffdebd43c3
commit
32a56e8387
5 changed files with 208 additions and 143 deletions
|
|
@ -245,7 +245,7 @@ class HomeSettingsService
|
|||
settings.rows.mapIndexed { index, config ->
|
||||
resolve(index, config)
|
||||
}
|
||||
HomePageResolvedSettings(resolvedRows)
|
||||
HomePageResolvedSettings(userId, resolvedRows)
|
||||
} else {
|
||||
createDefault(userId)
|
||||
}
|
||||
|
|
@ -256,12 +256,15 @@ class HomeSettingsService
|
|||
/**
|
||||
* Resolve the settings and set them to be the current settings
|
||||
*/
|
||||
suspend fun updateCurrent(settings: HomePageSettings) {
|
||||
suspend fun updateCurrent(
|
||||
userId: UUID,
|
||||
settings: HomePageSettings,
|
||||
) {
|
||||
val resolvedRows =
|
||||
settings.rows.mapIndexed { index, config ->
|
||||
resolve(index, config)
|
||||
}
|
||||
val resolvedSettings = HomePageResolvedSettings(resolvedRows)
|
||||
val resolvedSettings = HomePageResolvedSettings(userId, resolvedRows)
|
||||
currentSettings.update { resolvedSettings }
|
||||
}
|
||||
|
||||
|
|
@ -312,7 +315,7 @@ class HomeSettingsService
|
|||
),
|
||||
)
|
||||
val rowConfig = continueWatchingRow + includedIds
|
||||
return HomePageResolvedSettings(rowConfig)
|
||||
return HomePageResolvedSettings(userId, rowConfig)
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -428,7 +431,7 @@ class HomeSettingsService
|
|||
null
|
||||
}
|
||||
}.flatten()
|
||||
HomePageResolvedSettings(rowConfigs)
|
||||
HomePageResolvedSettings(userId, rowConfigs)
|
||||
} else {
|
||||
null
|
||||
}
|
||||
|
|
@ -1224,10 +1227,11 @@ data class HomeRowConfigDisplay(
|
|||
* @see HomePageSettings
|
||||
*/
|
||||
data class HomePageResolvedSettings(
|
||||
val userId: UUID,
|
||||
val rows: List<HomeRowConfigDisplay>,
|
||||
) {
|
||||
companion object {
|
||||
val EMPTY = HomePageResolvedSettings(listOf())
|
||||
val EMPTY = HomePageResolvedSettings(UUID.randomUUID(), emptyList())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -27,9 +27,6 @@ class SetupNavigationManager
|
|||
fun navigateTo(destination: SetupDestination) {
|
||||
backStack[0] = destination
|
||||
log()
|
||||
if (destination !is SetupDestination.AppContent) {
|
||||
navigationManager.reloadHome()
|
||||
}
|
||||
}
|
||||
|
||||
private fun log() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue