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

60s delay from the first device's connectes to activate wals, 120 mis… #996

Merged
merged 1 commit into from
Oct 7, 2024

Conversation

beastoin
Copy link
Collaborator

@beastoin beastoin commented Oct 7, 2024

…s seconds as threshold before displaying the 'sync now' to user.

Summary by Entelligence.AI

  • New Feature: Introduced a 'sync now' option for missing WALS, which becomes available based on a threshold of 120 seconds.
  • Refactor: Simplified the calculation of missing WALS in human-readable format for better performance and readability.
  • New Feature: Enabled the WALS feature based on device connection time and codec type, enhancing the app's adaptability to different devices.
  • Bug Fix: Added a check for mounted in the onboarding wrapper to prevent potential errors during setup functions execution.

…s seconds as threshold before displaying the 'sync now' to user.
@beastoin beastoin merged commit 0cb14ad into main Oct 7, 2024
1 check passed
@beastoin beastoin deleted the jzecm_wal_local_sync_958 branch October 7, 2024 22:30
Copy link

github-actions bot commented Oct 7, 2024

Image description Entelligence.AI

Walkthrough

This update enhances the handling of Write-Ahead Logs (WALs) by introducing a threshold-based 'sync now' option and simplifying missing WALs calculation. It also improves device connection time tracking and codec type-based WALS feature enablement. Lastly, it adds a check for mounted in the onboarding wrapper to ensure setup functions are executed properly.

Changes

Files Summary
app/lib/pages/memories/page.dart, app/lib/providers/memory_provider.dart Updated the condition for displaying the 'sync now' option based on a 120-second threshold. Simplified the calculation of missing WALS in human-readable format. Renamed _wal to _walService and updated method calls accordingly.
app/lib/providers/capture_provider.dart, app/lib/services/devices.dart Enabled the WALS feature based on device connection time and codec type. Added a new dependency on devices.dart for device-related functionality. Introduced a new method getFirstConnectedAt() to retrieve the timestamp when the first device was connected.
app/lib/pages/onboarding/wrapper.dart Added a check for mounted before executing setup functions in the _OnboardingWrapperState class.

🎉🤖

With each commit we grow,

In the codebase, improvements show.

From WALs to devices, we flow,

Making sure our progress never slows! 🚀


Uplevel your code reviews with Entelligence.AI Pro

Entelligence.AI Pro

If you like this project, please support us by purchasing the Pro version. The Pro version has advanced context, superior noise reduction and several proprietary improvements compared to the open source version. Moreover, Entelligence.AI Pro is free for open source projects.

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Image description Entelligence.AI

Commits Files that changed from the base of the PR and between 614ec36 and f8779fd commits.
Files selected (5)
  • app/lib/pages/memories/page.dart (2)
  • app/lib/pages/onboarding/wrapper.dart (1)
  • app/lib/providers/capture_provider.dart (3)
  • app/lib/providers/memory_provider.dart (4)
  • app/lib/services/devices.dart (3)
Files skipped from review due to trivial changes (1)
  • app/lib/services/devices.dart
Review comments generated (10)
  • Review: 5
  • LGTM: 5

Tips

Chat with Image description Entelligence.AI Bot (@Entelligence.AI)

  • Reply on review comments left by this bot to ask follow-up questions. A review comment is a comment on a diff or a file.
  • Invite the bot into a review comment chain by tagging @Entelligence.AI in a reply.

Code suggestions

  • The bot may make code suggestions, but please review them carefully before committing since the line number ranges may be misaligned.
  • You can edit the comment made by the bot and manually tweak the suggestion if it is slightly off.

Pausing incremental reviews

  • Add @Entelligence.AI: ignore anywhere in the PR description to pause further reviews from the bot.

Comment on lines +44 to +47
if (mounted) {
context.read<HomeProvider>().setupHasSpeakerProfile();
_goNext();
}
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

Good addition of the mounted check before executing setup functions. This will prevent potential exceptions that could occur if these methods are called after the widget is disposed.

+    if (mounted) {
+      context.read<HomeProvider>().setupHasSpeakerProfile();
+      _goNext();
+    }

This change ensures that the setup functions are only called when the widget is still active in the widget tree, which improves the robustness of the code.

@@ -79,7 +79,7 @@ class _MemoriesPageState extends State<MemoriesPage> with AutomaticKeepAliveClie
child: CustomScrollView(
slivers: [
SliverToBoxAdapter(
child: memoryProvider.missingWals.isNotEmpty
child: memoryProvider.missingWalsInSeconds > 120
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 change from checking if missingWals is not empty to checking if missingWalsInSeconds is greater than 120 seconds seems to be a significant logic change. Ensure that this new condition aligns with the intended functionality. If the intention is to only show the 'sync now' option when there are more than 120 seconds of unsynced data, then this change is correct.

- child: memoryProvider.missingWals.isNotEmpty
+ child: memoryProvider.missingWalsInSeconds > 120

@@ -95,7 +95,7 @@ class _MemoriesPageState extends State<MemoriesPage> with AutomaticKeepAliveClie
child: ListTile(
leading: const Icon(Icons.record_voice_over_rounded),
title: Text(
'You have ${secondsToHumanReadable(memoryProvider.missingWals.map((val) => val.seconds).reduce((a, b) => a + b))} of conversation locally, sync now?',
'You have ${secondsToHumanReadable(memoryProvider.missingWalsInSeconds)} of conversation locally, sync now?',
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 change in how the human-readable time for missing WALs is calculated simplifies the code and makes it easier to understand. However, ensure that missingWalsInSeconds is always updated correctly whenever a new WAL is added or an existing one is removed or modified.

- 'You have ${secondsToHumanReadable(memoryProvider.missingWals.map((val) => val.seconds).reduce((a, b) => a + b))} of conversation locally, sync now?'
+ 'You have ${secondsToHumanReadable(memoryProvider.missingWalsInSeconds)} of conversation locally, sync now?'

Comment on lines +45 to +47
bool _walFeatureEnabled = true;
IWalService get _walService => ServiceManager.instance().wal;
IDeviceService get _deviceService => ServiceManager.instance().device;
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 renaming of _wal to _walService and the introduction of _deviceService are good changes for clarity and maintainability. However, I would suggest adding null checks before using these services throughout your code to prevent potential null pointer exceptions.

-   IWalService get _walService => ServiceManager.instance().wal;
-   IDeviceService get _deviceService => ServiceManager.instance().device;
+   IWalService? get _walService => ServiceManager.instance().wal;
+   IDeviceService? get _deviceService => ServiceManager.instance().device;

Comment on lines +158 to +175
// support: opus codec, 1m from the first device connectes
var deviceFirstConnectedAt = _deviceService.getFirstConnectedAt();
var isWalEnabled = codec == BleAudioCodec.opus &&
(deviceFirstConnectedAt != null &&
deviceFirstConnectedAt.isBefore(DateTime.now().subtract(const Duration(seconds: 60)))) &&
_walFeatureEnabled;
if (isWalEnabled) {
_walService.onByteStream(value);
}

// send ws
if (_socket?.state == SocketServiceState.connected) {
final trimmedValue = value.sublist(3);
_socket?.send(trimmedValue);

// synced
if (isWalSupported) {
_wal.onBytesSync(value);
if (isWalEnabled) {
_walService.onBytesSync(value);
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 logic here is a bit complex and could be simplified for better readability. Also, it's important to handle the case when getFirstConnectedAt() returns null. Here's a suggested refactor:

-       var deviceFirstConnectedAt = _deviceService.getFirstConnectedAt();
-       var isWalEnabled = codec == BleAudioCodec.opus &&
-           (deviceFirstConnectedAt != null &&
-               deviceFirstConnectedAt.isBefore(DateTime.now().subtract(const Duration(seconds: 60)))) &&
-           _walFeatureEnabled;
-       if (isWalEnabled) {
-         _walService.onByteStream(value);
-        }
-
-       // send ws
-        if (_socket?.state == SocketServiceState.connected) {
-          final trimmedValue = value.sublist(3);
-          _socket?.send(trimmedValue);
-
-          // synced
-         if (isWalEnabled) {
-           _walService.onBytesSync(value);
-         }
-       }
+       var deviceFirstConnectedAt = _deviceService?.getFirstConnectedAt();
+       var isWalEnabled = _walFeatureEnabled && codec == BleAudioCodec.opus &&
+           deviceFirstConnectedAt?.isBefore(DateTime.now().subtract(const Duration(seconds: 60))) == true;
+
+       if (isWalEnabled) {
+         _walService?.onByteStream(value);
+       }
+
+       if (_socket?.state == SocketServiceState.connected) {
+         final trimmedValue = value.sublist(3);
+         _socket?.send(trimmedValue);
+
+         if (isWalEnabled) {
+           _walService?.onBytesSync(value);
+         }
+       }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant