perf(app): the dashboard works itself out once a burst of changes ends
The home tab stays open below a study session, and every rating changed what it shows; it now waits until changes pause for 300 ms, so a large library isn't read anew after each rating. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Tizian 「ティツィアーン」 <raisondetredev@pm.me>
This commit is contained in:
parent
111532435f
commit
a52e96b27c
1 changed files with 18 additions and 1 deletions
|
|
@ -57,8 +57,24 @@ class HomeBloc(
|
||||||
/// out never overwrites a newer one.
|
/// out never overwrites a newer one.
|
||||||
var _refreshes = 0;
|
var _refreshes = 0;
|
||||||
|
|
||||||
|
/// Waits for a burst of changes to end, e.g. ratings in a study session
|
||||||
|
/// while this tab stays open below it, so the dashboard is worked out once
|
||||||
|
/// rather than after every one.
|
||||||
|
Timer? _settling;
|
||||||
|
|
||||||
|
/// How long changes must pause before the dashboard is worked out anew.
|
||||||
|
static const settleTime = Duration(milliseconds: 300);
|
||||||
|
|
||||||
void _onStarted(HomeEventStarted event, Emitter<HomeState> emit) {
|
void _onStarted(HomeEventStarted event, Emitter<HomeState> emit) {
|
||||||
void changed(Object? _) => add(const HomeEventChanged());
|
void changed(Object? _) {
|
||||||
|
_settling?.cancel();
|
||||||
|
_settling = Timer(settleTime, () {
|
||||||
|
if (!isClosed) {
|
||||||
|
add(const HomeEventChanged());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
_subscriptions.addAll([
|
_subscriptions.addAll([
|
||||||
_reviews.changes.listen(changed),
|
_reviews.changes.listen(changed),
|
||||||
_cards.changes.listen(changed),
|
_cards.changes.listen(changed),
|
||||||
|
|
@ -125,6 +141,7 @@ class HomeBloc(
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> close() async {
|
Future<void> close() async {
|
||||||
|
_settling?.cancel();
|
||||||
for (final subscription in _subscriptions) {
|
for (final subscription in _subscriptions) {
|
||||||
await subscription.cancel();
|
await subscription.cancel();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue