fix(#517): review round 2 - back off failed pref reads, one derivation for the drawer's hidden-in-view set

This commit is contained in:
makiolaj committed 2026-11-14 12:09:19 +01:00
1 parent 8df21b965a
commit 95c40c9d88
4 files changed
+15 -14

No files matched your search

@@ -40,14 +40,16 @@ fun Flow<Map<Long, Set<CalendarView>>>.calendarsHiddenIn(
* shows it, and keeps reading, so the next change still lands.
*/
fun Flow<Map<Long, Set<CalendarView>>>.hidingNothingOnError(): Flow<Map<Long, Set<CalendarView>>> =
retryWhen { cause, _ ->
retryWhen { cause, attempt ->
if (cause !is IOException) return@retryWhen false
emit(emptyMap())
delay(RETRY_DELAY_MS)
// Backs off, so a file that keeps failing (corrupt) isn't re-read every second.
delay((RETRY_BASE_DELAY_MS shl attempt.coerceAtMost(6).toInt()).coerceAtMost(RETRY_MAX_DELAY_MS))
true
}
private const val RETRY_DELAY_MS = 1_000L
private const val RETRY_BASE_DELAY_MS = 1_000L
private const val RETRY_MAX_DELAY_MS = 60_000L
/**
* [CalendarRepository.instances] as one view shows them: also without the
@@ -31,7 +31,6 @@ import de.jeanlucmakiola.calendula.domain.FailureReason
import de.jeanlucmakiola.calendula.ui.common.CalendarAccountGroup
import de.jeanlucmakiola.calendula.ui.common.CalendarColorChip
import de.jeanlucmakiola.calendula.ui.common.CalendarView
import de.jeanlucmakiola.calendula.ui.common.calendarsHiddenIn
import de.jeanlucmakiola.calendula.ui.common.accountGroupTitle
import de.jeanlucmakiola.calendula.ui.common.orUnnamed
import de.jeanlucmakiola.floret.components.GroupedListInset
@@ -59,12 +58,12 @@ fun CalendarFilterList(
FilterUiState.Loading -> FilterLoading(modifier)
is FilterUiState.Failure -> FilterMessage(s.reason, modifier)
is FilterUiState.Success -> {
val hiddenInView = remember(s, currentView) { s.hiddenViews.calendarsHiddenIn(currentView) - s.hidden }
val hiddenInView = remember(s, currentView) { s.hiddenOnlyIn(currentView) }
FilterList(
groups = s.groups,
hidden = s.hidden,
hiddenInView = hiddenInView,
hiddenOnlyHere = remember(s, currentView) { s.hiddenOnlyIn(currentView) },
hiddenOnlyHere = hiddenInView.size,
onHideInView = onHideInView,
onSetVisible = viewModel::setVisible,
modifier = modifier,
@@ -23,12 +23,12 @@ sealed interface FilterUiState {
val hiddenViews: Map<Long, Set<CalendarView>> = emptyMap(),
) : FilterUiState {
/**
* How many listed calendars [view] hides on its own (#517); ones already
* hidden everywhere from the drawer, or not listed, don't count.
* The listed calendars [view] hides on its own (#517); ones already
* hidden everywhere from the drawer, or not listed, aren't included.
*/
fun hiddenOnlyIn(view: CalendarView): Int {
fun hiddenOnlyIn(view: CalendarView): Set<Long> {
val listed = groups.flatMapTo(mutableSetOf()) { group -> group.calendars.map { it.id } }
return hiddenViews.calendarsHiddenIn(view).count { it in listed && it !in hidden }
return hiddenViews.calendarsHiddenIn(view).filterTo(mutableSetOf()) { it in listed && it !in hidden }
}
}
}
@@ -11,7 +11,7 @@ class FilterUiStateTest {
private fun calendar(id: Long) = CalendarSource(id, "Cal $id", "x@y", "LOCAL", 0, true)
@Test
fun `hiddenOnlyIn counts listed calendars the view hides on its own`() {
fun `hiddenOnlyIn lists the calendars the view hides on its own`() {
val state = FilterUiState.Success(
groups = listOf(calendar(1L), calendar(2L), calendar(3L)).groupByAccount(),
// 3 is hidden everywhere from the drawer already.
@@ -24,8 +24,8 @@ class FilterUiStateTest {
9L to setOf(CalendarView.Month),
),
)
assertThat(state.hiddenOnlyIn(CalendarView.Month)).isEqualTo(2)
assertThat(state.hiddenOnlyIn(CalendarView.Week)).isEqualTo(1)
assertThat(state.hiddenOnlyIn(CalendarView.Agenda)).isEqualTo(0)
assertThat(state.hiddenOnlyIn(CalendarView.Month)).containsExactly(1L, 2L)
assertThat(state.hiddenOnlyIn(CalendarView.Week)).containsExactly(2L)
assertThat(state.hiddenOnlyIn(CalendarView.Agenda)).isEmpty()
}
}