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

+28 -9
View File
@@ -95,6 +95,8 @@ final class TimelineViewStateBinding {
session,
repository,
);
binding._savedViews.addAll(saved.sequences);
binding._savedActiveSequenceId = saved.activeSequenceId;
for (final sequenceId in sequenceIds) {
final controller = session.view(sequenceId);
void listener() => binding._schedule(sequenceId);
@@ -133,6 +135,8 @@ final class TimelineViewStateBinding {
final EditorTimelineSession session;
final TimelineViewSettingsRepository repository;
final Map<SequenceId, void Function()> _listeners = {};
final Map<SequenceId, TimelineSequenceViewState> _savedViews = {};
SequenceId? _savedActiveSequenceId;
SequenceId? _activeSequenceId;
Timer? _timer;
Future<void> _tail = Future.value();
@@ -162,21 +166,36 @@ final class TimelineViewStateBinding {
Future<void> _save(SequenceId sequenceId) async {
final controller = session.view(sequenceId);
final value = TimelineSequenceViewState(
playheadTick: controller.playheadTick,
camera: controller.camera,
);
// Selection notifications and closing can repeat the last persisted view.
// A sequence switch must still update the repository's active sequence.
if (_savedActiveSequenceId == sequenceId &&
_sameView(_savedViews[sequenceId], value)) {
return;
}
try {
await repository.save(
projectId,
timelineId,
sequenceId,
TimelineSequenceViewState(
playheadTick: controller.playheadTick,
camera: controller.camera,
),
);
await repository.save(projectId, timelineId, sequenceId, value);
_savedViews[sequenceId] = value;
_savedActiveSequenceId = sequenceId;
} catch (_) {
// View state must never block editing or project persistence.
}
}
static bool _sameView(
TimelineSequenceViewState? saved,
TimelineSequenceViewState next,
) =>
saved != null &&
saved.playheadTick == next.playheadTick &&
saved.camera.baseTick == next.camera.baseTick &&
saved.camera.fractionalTick == next.camera.fractionalTick &&
saved.camera.pixelsPerTick == next.camera.pixelsPerTick &&
saved.camera.verticalOffset == next.camera.verticalOffset;
Future<void> close() async {
if (_closed) return;
_closed = true;