perf(settings): batch and deduplicate writes and persist panel dimensions

This commit is contained in:
lingjhf committed 2026-10-09 19:20:54 +08:00
1 parent bc3fdd6119
commit 02413383d8
23 files changed
+869 -83

No files matched your search

+49
View File
@@ -90,6 +90,55 @@ void _testSettings<T>({
required T Function(ProviderContainer) value,
required Future<void> Function(ProviderContainer, T) save,
}) {
test('$name skips an unchanged loaded value', () async {
final store = _Store(initial);
final scope = container(store);
addTearDown(scope.dispose);
await load(scope);
await save(scope, initial);
expect(store.writes, isEmpty);
});
test('$name skips duplicate values queued during a write', () async {
final store = _Store(initial)..writeGate = Completer<void>();
final scope = container(store);
addTearDown(scope.dispose);
await load(scope);
final firstSave = save(scope, first);
await store.started.future;
final duplicates = List.generate(5, (_) => save(scope, first));
store.writeGate!.complete();
await Future.wait([firstSave, ...duplicates]);
expect(store.writes, [first]);
expect(value(scope), first);
});
test('$name preserves changes back to a previously saved value', () async {
final store = _Store(initial);
final scope = container(store);
addTearDown(scope.dispose);
await load(scope);
await Future.wait([
save(scope, first),
save(scope, second),
save(scope, first),
]);
expect(store.writes, [first, second, first]);
expect(store.value, first);
});
test('$name retries the same value after a failed write', () async {
final store = _Store(initial)..failWrites = true;
final scope = container(store);
addTearDown(scope.dispose);
await load(scope);
await expectLater(save(scope, first), throwsStateError);
store.failWrites = false;
await save(scope, first);
expect(store.writes, [first, first]);
expect(store.value, first);
});
test('$name saves in order and publishes only committed values', () async {
final store = _Store(initial)..writeGate = Completer<void>();
final scope = container(store);