Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes the local sync timer #1011

Merged
merged 1 commit into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/lib/pages/memories/page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ class _MemoriesPageState extends State<MemoriesPage> with AutomaticKeepAliveClie
},
child: CustomScrollView(
slivers: [
const SliverToBoxAdapter(child: SizedBox(height: 26)),
const SliverToBoxAdapter(child: SpeechProfileCardWidget()),
const SliverToBoxAdapter(child: UpdateFirmwareCardWidget()),
const SliverToBoxAdapter(child: LocalSyncWidget()),
Expand Down
34 changes: 21 additions & 13 deletions app/lib/pages/memories/widgets/local_sync.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,29 +38,37 @@ class _LocalSyncWidgetState extends State<LocalSyncWidget> {
@override
Widget build(BuildContext context) {
return Consumer2<MemoryProvider, CaptureProvider>(builder: (context, provider, captureProvider, child) {
var previousStatus = _status;
if (provider.missingWalsInSeconds > 120) {
_status = LocalSyncStatus.flush;
_missSeconds = max(_missSeconds, provider.missingWalsInSeconds); // est. good for ux
} else if (!captureProvider.isWalSupported) {
_status = LocalSyncStatus.disabled;
_missSecondsInEstTimer?.cancel();
} else if ((!captureProvider.transcriptServiceReady && captureProvider.recordingDeviceServiceReady) ||
provider.missingWalsInSeconds > 0) {
var previousStatus = _status;
} else if (provider.missingWalsInSeconds > 0) {
_status = LocalSyncStatus.inProgress;
} else {
_status = LocalSyncStatus.disabled;
}

// Change state to in progress
if (previousStatus != LocalSyncStatus.inProgress) {
_missSecondsInEstTimer?.cancel();
// miss seconds
if (_status == LocalSyncStatus.inProgress || _status == LocalSyncStatus.flush) {
if (previousStatus != _status) {
_missSeconds = provider.missingWalsInSeconds;
_missSecondsInEstTimer = Timer.periodic(const Duration(seconds: 1), (t) {
setState(() {
_missSeconds++;
});
});
}
}

// timer
if ((_status == LocalSyncStatus.inProgress || _status == LocalSyncStatus.flush) &&
(!captureProvider.transcriptServiceReady && captureProvider.recordingDeviceServiceReady)) {
_missSecondsInEstTimer ??= Timer.periodic(const Duration(seconds: 1), (t) {
setState(() {
_missSeconds++;
});
});
} else {
_missSecondsInEstTimer?.cancel();
_missSecondsInEstTimer = null;
}
Comment on lines +41 to +70
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Image description Entelligence.AI

The refactoring of the timer and status logic seems to have introduced a potential issue. In the new code, _missSeconds is only updated when the status changes from another status to LocalSyncStatus.inProgress or LocalSyncStatus.flush. However, in the old code, _missSeconds was updated every time the build method was called and the status was LocalSyncStatus.inProgress or LocalSyncStatus.flush, regardless of whether the status had just changed.

This could lead to _missSeconds not being updated correctly if the build method is called multiple times without the status changing, which could happen due to various reasons such as other state changes in the widget triggering a rebuild.

Here's a suggested fix:

      if (_status == LocalSyncStatus.inProgress || _status == LocalSyncStatus.flush) {
        if (previousStatus != _status) {
           _missSeconds = provider.missingWalsInSeconds;
         }
       }

Replace with:

+ 53:       if (_status == LocalSyncStatus.inProgress || _status == LocalSyncStatus.flush) {
+ 54:           _missSeconds = provider.missingWalsInSeconds;
+ 55:        }

This will ensure that _missSeconds is always updated correctly when the status is LocalSyncStatus.inProgress or LocalSyncStatus.flush, even if the status hasn't just changed.


// in progress
if (_status == LocalSyncStatus.inProgress) {
return Container(
Expand Down
Loading