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

Add sync progress #991

Merged
merged 1 commit into from
Oct 7, 2024
Merged

Add sync progress #991

merged 1 commit into from
Oct 7, 2024

Conversation

beastoin
Copy link
Collaborator

@beastoin beastoin commented Oct 7, 2024

Summary by Entelligence.AI

  • New Feature: Introduced a progress tracking feature for the synchronization of Wals. Users can now monitor the progress of Wal synchronization in real-time.
  • Improvement: Enhanced the IWalSyncProgressListener interface to handle progress updates more efficiently and perform cleanup tasks for synced Wals.
  • Refactor: Modified the memories page to display different text based on the walsSyncedProgress value, improving user experience during Wal synchronization.

@beastoin beastoin merged commit 61ec210 into main Oct 7, 2024
1 check passed
@beastoin beastoin deleted the jzecm_wal_local_sync_958 branch October 7, 2024 10:11
Copy link

github-actions bot commented Oct 7, 2024

Image description Entelligence.AI

Walkthrough

This update introduces a new interface IWalSyncProgressListener and a progress tracking property walsSyncedProgress. It enhances the syncWals method to update progress during synchronization, and implements a new method onWalSyncedProgress for handling these updates. The changes also include a cleanup step for synced Wals and progress reporting during Wal syncing.

Changes

File Summary
app/lib/pages/memories/page.dart Modified child widget to display different text based on walsSyncedProgress value.
app/lib/providers/memory_provider.dart Added walsSyncedProgress property and updated syncWals method to track synchronization progress. Implemented onWalSyncedProgress method to handle progress updates.
app/lib/services/wals.dart Introduced IWalSyncProgressListener interface with modified onWalSyncedProgress signature. Added cleanup step for synced Wals and set their status accordingly.

🎉 With every sync, we make a stride,

Progress tracked, no place to hide.

From zero to one, in steps so small,

Celebrate, for we've synced them all! 🎉


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 92aa67b and cda9e0c commits.
Files selected (3)
  • app/lib/pages/memories/page.dart (1)
  • app/lib/providers/memory_provider.dart (3)
  • app/lib/services/wals.dart (4)
Review comments generated (9)
  • Review: 6
  • LGTM: 3

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 +59 to +62
child: memoryProvider.walsSyncedProgress == 0.0
? Text(
"You have ${memoryProvider.missingWals.map((val) => val.seconds).reduce((a, b) => a + b)}s stereo localy, sync now?")
: Text("${(memoryProvider.walsSyncedProgress * 100).toInt()}%"),
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 code assumes that memoryProvider.missingWals is not empty. If it's empty, calling reduce on it will throw an error. You should add a check to ensure missingWals is not empty before trying to reduce it.

- "You have ${memoryProvider.missingWals.map((val) => val.seconds).reduce((a, b) => a + b)}s stereo localy, sync now?")
+ "You have ${memoryProvider.missingWals.isNotEmpty ? memoryProvider.missingWals.map((val) => val.seconds).reduce((a, b) => a + b) : 0}s stereo localy, sync now?")

Also, there's a typo in the word 'locally'. It should be corrected as well.

- "You have ${memoryProvider.missingWals.isNotEmpty ? memoryProvider.missingWals.map((val) => val.seconds).reduce((a, b) => a + b) : 0}s stereo localy, sync now?")
+ "You have ${memoryProvider.missingWals.isNotEmpty ? memoryProvider.missingWals.map((val) => val.seconds).reduce((a, b) => a + b) : 0}s stereo locally, sync now?")

@@ -11,7 +11,7 @@ import 'package:friend_private/services/wals.dart';
import 'package:friend_private/utils/analytics/mixpanel.dart';
import 'package:friend_private/utils/features/calendar.dart';

class MemoryProvider extends ChangeNotifier implements IWalServiceListener {
class MemoryProvider extends ChangeNotifier implements IWalServiceListener, IWalSyncProgressListener {
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 class MemoryProvider now implements the IWalSyncProgressListener interface. Ensure that all methods from this interface are properly implemented in this class.

- class MemoryProvider extends ChangeNotifier implements IWalServiceListener {
+ class MemoryProvider extends ChangeNotifier implements IWalServiceListener, IWalSyncProgressListener {

Comment on lines +329 to +335
_walsSyncedProgress = 0.0;
_wal.syncAll(progress: this);
}

@override
void onWalSyncedProgress(double percentage) {
_walsSyncedProgress = percentage;
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 syncWals method has been updated to reset _walsSyncedProgress to 0 before starting synchronization and to use the this object as a progress listener. The onWalSyncedProgress method is used to update _walsSyncedProgress. Make sure that the syncAll method of _wal correctly handles the progress parameter and that it calls onWalSyncedProgress at appropriate times during the synchronization process.

-    _wal.syncAll();
+    _walsSyncedProgress = 0.0;
+    _wal.syncAll(progress: this);
+   @override
+   void onWalSyncedProgress(double percentage) {
+     _walsSyncedProgress = percentage;
+   }

@@ -108,7 +108,7 @@ class Wal {
}

abstract class IWalSyncProgressListener {
void onWalSyncedProgress(Wal wal, Float percentage);
void onWalSyncedProgress(double percentage); // 0..1
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 method signature for onWalSyncedProgress has been changed to accept a double value representing the percentage of progress. This is a breaking change if there are any existing implementations of IWalSyncProgressListener. Make sure all implementations are updated accordingly.

- void onWalSyncedProgress(Wal wal, Float percentage);
+ void onWalSyncedProgress(double percentage); // 0..1

Comment on lines +267 to +272
// Clean synced wal
for (var i = _wals.length - 1; i >= 0; i--) {
if (_wals[i].status == WalStatus.synced) {
await _deleteWal(_wals[i]);
}
}
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

This block of code deletes all Wals that have been synced. However, it's not clear whether _deleteWal(_wals[i]) is an asynchronous operation that could potentially fail. If it does fail, the error is not being handled here which could lead to inconsistencies in the state of your application. Consider adding error handling around this operation.

-        await _deleteWal(_wals[i]);
+        try {
+          await _deleteWal(_wals[i]);
+        } catch (e) {
+          // Handle or log error
+        }

Comment on lines +451 to 456
_wals[j].status = WalStatus.synced;

// Send
for (var sub in _subscriptions.values) {
sub.onWalSynced(wal);
sub.onWalSynced(_wals[j]);
}
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

This block notifies all subscribers that a Wal has been synced. However, it doesn't handle potential errors that might occur during the notification process. If any subscriber throws an error, it will stop the execution and other subscribers might not get notified. Consider adding error handling to ensure all subscribers are notified even if one fails.

-         sub.onWalSynced(_wals[j]);
+         try {
+           sub.onWalSynced(_wals[j]);
+         } catch (e) {
+           // Handle or log error
+         }

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