Don't debounce the agenda query in the clock widget
`CalendarRepository.findMany` holds every result back by 500 ms, which was added for the calendar widget to collapse bursts of plugin and permission changes. `debounce` delays the first result too, so the agenda part - whose ranking stays 0 until the first result arrives - only appeared half a second after the clock and the other parts. The agenda is re-queried on a calendar change or every 15 minutes, so it does not need the debounce. Make the delay a parameter (still 500 ms by default) and pass 0 from `CalendarPartProvider`.
This commit is contained in:
@@ -122,6 +122,10 @@ class CalendarPartProvider : PartProvider, KoinComponent {
|
|||||||
from = now,
|
from = now,
|
||||||
to = endOfDay(now),
|
to = endOfDay(now),
|
||||||
excludeCalendars = excludedCalendars.toList(),
|
excludeCalendars = excludedCalendars.toList(),
|
||||||
|
// No debounce: the ranking stays 0 until the first result arrives, and
|
||||||
|
// the query is only re-run on a calendar change or every 15 minutes, so
|
||||||
|
// holding the result back would only delay the part's appearance.
|
||||||
|
debounceMillis = 0,
|
||||||
).first()
|
).first()
|
||||||
.filter { !it.isTask }
|
.filter { !it.isTask }
|
||||||
.sortedBy { it.startTime ?: it.endTime }
|
.sortedBy { it.startTime ?: it.endTime }
|
||||||
|
|||||||
@@ -31,11 +31,17 @@ import kotlinx.coroutines.supervisorScope
|
|||||||
import kotlin.time.Duration.Companion.days
|
import kotlin.time.Duration.Companion.days
|
||||||
|
|
||||||
interface CalendarRepository : SearchableRepository<CalendarEvent> {
|
interface CalendarRepository : SearchableRepository<CalendarEvent> {
|
||||||
|
/**
|
||||||
|
* @param debounceMillis how long each result is held back, so bursts of upstream changes
|
||||||
|
* (plugin or permission updates) cause a single query. [debounce] delays the first result
|
||||||
|
* too, so callers that must show something immediately pass 0.
|
||||||
|
*/
|
||||||
fun findMany(
|
fun findMany(
|
||||||
from: Long = System.currentTimeMillis(),
|
from: Long = System.currentTimeMillis(),
|
||||||
to: Long = from + 14 * 24 * 60 * 60 * 1000L,
|
to: Long = from + 14 * 24 * 60 * 60 * 1000L,
|
||||||
excludeCalendars: List<String> = emptyList(),
|
excludeCalendars: List<String> = emptyList(),
|
||||||
excludeAllDayEvents: Boolean = false,
|
excludeAllDayEvents: Boolean = false,
|
||||||
|
debounceMillis: Long = 500,
|
||||||
): Flow<ImmutableList<CalendarEvent>>
|
): Flow<ImmutableList<CalendarEvent>>
|
||||||
|
|
||||||
fun getCalendars(providerId: String? = null): Flow<List<CalendarList>>
|
fun getCalendars(providerId: String? = null): Flow<List<CalendarList>>
|
||||||
@@ -94,6 +100,7 @@ internal class CalendarRepositoryImpl(
|
|||||||
to: Long,
|
to: Long,
|
||||||
excludeCalendars: List<String>,
|
excludeCalendars: List<String>,
|
||||||
excludeAllDayEvents: Boolean,
|
excludeAllDayEvents: Boolean,
|
||||||
|
debounceMillis: Long,
|
||||||
): Flow<ImmutableList<CalendarEvent>> {
|
): Flow<ImmutableList<CalendarEvent>> {
|
||||||
val hasCalendarPermission = permissionsManager.hasPermission(PermissionGroup.Calendar)
|
val hasCalendarPermission = permissionsManager.hasPermission(PermissionGroup.Calendar)
|
||||||
val hasTasksPermission = permissionsManager.hasPermission(PermissionGroup.Tasks)
|
val hasTasksPermission = permissionsManager.hasPermission(PermissionGroup.Tasks)
|
||||||
@@ -112,17 +119,16 @@ internal class CalendarRepositoryImpl(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
emitAll(
|
val events = queryCalendarEvents(
|
||||||
queryCalendarEvents(
|
query = null,
|
||||||
query = null,
|
intervalStart = from,
|
||||||
intervalStart = from,
|
intervalEnd = to,
|
||||||
intervalEnd = to,
|
excludeAllDayEvents = excludeAllDayEvents,
|
||||||
excludeAllDayEvents = excludeAllDayEvents,
|
excludeCalendars = excludeCalendars,
|
||||||
excludeCalendars = excludeCalendars,
|
providers = providers,
|
||||||
providers = providers,
|
allowNetwork = false,
|
||||||
allowNetwork = false,
|
|
||||||
).debounce(500)
|
|
||||||
)
|
)
|
||||||
|
emitAll(if (debounceMillis > 0L) events.debounce(debounceMillis) else events)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user