Simplify series overview page refresh (#1092)

## Description
This PR simplifies refreshing the episode data when returning to the
series overview page and reduces the number of queries.

Also fixes a race condition when refreshing a single item in the an
`ApiRequestPager`.

### Related issues
Related to #767

### Testing
Emulator, but will need more testing during actual usage

## Screenshots
N/A

## AI or LLM usage
None
This commit is contained in:
Ray 2026-03-12 21:16:56 -04:00 committed by GitHub
parent 62965c1b22
commit 8bc3384094
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 10 additions and 30 deletions

View file

@ -125,20 +125,6 @@ fun SeriesOverview(
var rowFocused by rememberInt()
var showDeleteDialog by remember { mutableStateOf<BaseItem?>(null) }
LaunchedEffect(episodes) {
episodes?.let { episodes ->
if (episodes is EpisodeList.Success) {
if (episodes.episodes.isNotEmpty()) {
// TODO focus on first episode when changing seasons?
// firstItemFocusRequester.requestFocus()
episodes.episodes.getOrNull(position.episodeRowIndex)?.let {
viewModel.refreshEpisode(it.id, position.episodeRowIndex)
}
}
}
}
}
LaunchedEffect(position, episodes) {
val focusedEpisode =
(episodes as? EpisodeList.Success)

View file

@ -387,12 +387,6 @@ class SeriesViewModel
withContext(Dispatchers.Main) {
this@SeriesViewModel.episodes.value = episodes
}
if (currentEpisodes == null || currentEpisodes.seasonId != seasonId) {
(episodes as? EpisodeList.Success)
?.let {
it.episodes.getOrNull(it.initialEpisodeIndex)
}?.let { lookupPeopleInEpisode(it) }
}
}
}

View file

@ -146,17 +146,17 @@ class ApiRequestPager<T>(
position: Int,
itemId: UUID,
) {
val item =
api.userLibraryApi.getItem(itemId).content.let {
BaseItem.from(
it,
api,
useSeriesForPrimary,
)
}
val pageNumber = position / pageSize
val index = position - pageNumber * pageSize
mutex.withLock {
val item =
api.userLibraryApi.getItem(itemId).content.let {
BaseItem.from(
it,
api,
useSeriesForPrimary,
)
}
val pageNumber = position / pageSize
val index = position - pageNumber * pageSize
val page = cachedPages.getIfPresent(pageNumber)
if (page != null && index in page.indices) {
page[index] = item