-
Notifications
You must be signed in to change notification settings - Fork 5
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
Avoid unnecessary syncs in push-only sync mode #188
Conversation
WalkthroughThe recent updates to the Yorkie project primarily focus on enhancing synchronization functionality and testing. New methods and imports have been added to facilitate better real-time synchronization and to test these features more effectively. Specifically, a new test method was introduced to avoid unnecessary syncs, and a method was added to determine the need for real-time synchronization. Additionally, a timeout constant was standardized across tests. Changes
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
Review Details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (4)
- yorkie/src/androidTest/kotlin/dev/yorkie/core/ClientTest.kt (2 hunks)
- yorkie/src/androidTest/kotlin/dev/yorkie/document/json/JsonTreeConcurrencyTest.kt (2 hunks)
- yorkie/src/main/kotlin/dev/yorkie/core/Attachment.kt (1 hunks)
- yorkie/src/main/kotlin/dev/yorkie/core/Client.kt (1 hunks)
Additional comments not posted (5)
yorkie/src/main/kotlin/dev/yorkie/core/Attachment.kt (1)
12-18
: The implementation ofneedRealTimeSync
method correctly handles the sync logic based onsyncMode
. This should effectively reduce unnecessary sync operations in push-only mode.yorkie/src/androidTest/kotlin/dev/yorkie/document/json/JsonTreeConcurrencyTest.kt (1)
5-5
: Replacing hardcoded timeout values withGENERAL_TIMEOUT
is a good practice for maintainability and ensures consistency across tests.yorkie/src/main/kotlin/dev/yorkie/core/Client.kt (1)
185-185
: The modification to useneedRealTimeSync
from theAttachment
class centralizes the sync logic, enhancing maintainability and reducing code duplication. Ensure this change integrates well with the rest of the system.Verification successful
The
needRealTimeSync
method in theAttachment
class is correctly implemented and checks thesyncMode
to determine if real-time synchronization is needed. The integration of this method in thefilterRealTimeSyncNeeded
function centralizes the sync logic, enhancing maintainability and reducing code duplication.
Attachment.kt
:internal data class Attachment( val document: Document, val documentID: String, val syncMode: Client.SyncMode = Client.SyncMode.Realtime, val remoteChangeEventReceived: Boolean = false, ) { fun needRealTimeSync(): Boolean { return if (syncMode == Client.SyncMode.RealtimePushOnly) { document.hasLocalChanges } else { syncMode.needRealTimeSync } } }This change is well-implemented and should integrate seamlessly with the rest of the system.
Scripts Executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify integration of `filterRealTimeSyncNeeded` with the system. # Test: Search for the function usage. Expect: Only occurances of the new signature. rg --type kotlin $'filterRealTimeSyncNeeded'Length of output: 321
Script:
#!/bin/bash # Description: Verify the implementation and usage of `needRealTimeSync` in the `Attachment` class. # Locate the `needRealTimeSync` method in the `Attachment` class. ast-grep --lang kotlin --pattern $'class Attachment { $$$ fun needRealTimeSync(): Boolean { $$$ } $$$ }' # Search for the usage of `needRealTimeSync` method across the codebase. rg --type kotlin 'needRealTimeSync'Length of output: 538
Script:
#!/bin/bash # Description: Extract the implementation details of `needRealTimeSync` method and `SyncMode` enum. # Extract the implementation of `needRealTimeSync` method in `Attachment.kt`. rg --type kotlin --context 10 'fun needRealTimeSync(): Boolean' yorkie/src/main/kotlin/dev/yorkie/core/Attachment.kt # Extract the implementation of `SyncMode` enum in `Attachment.kt`. rg --type kotlin --context 10 'enum class SyncMode' yorkie/src/main/kotlin/dev/yorkie/core/Attachment.ktLength of output: 225
Script:
#!/bin/bash # Description: Re-extract the implementation details of `needRealTimeSync` method and `SyncMode` enum with adjusted parameters. # Extract the implementation of `needRealTimeSync` method in `Attachment.kt` with increased context lines. rg --type kotlin --context 20 'fun needRealTimeSync(): Boolean' yorkie/src/main/kotlin/dev/yorkie/core/Attachment.kt # Extract the implementation of `SyncMode` enum in `Attachment.kt` with increased context lines. rg --type kotlin --context 20 'enum class SyncMode' yorkie/src/main/kotlin/dev/yorkie/core/Attachment.ktLength of output: 225
Script:
#!/bin/bash # Description: Locate the `Attachment` class and inspect its methods and properties. # Locate the `Attachment` class definition. rg --type kotlin --context 20 'class Attachment' yorkie/src/main/kotlin/dev/yorkie/core/Attachment.kt # Locate all methods in the `Attachment` class. ast-grep --lang kotlin --pattern $'class Attachment { $$$ fun $_($_): $_ { $$$ } $$$ }'Length of output: 688
yorkie/src/androidTest/kotlin/dev/yorkie/core/ClientTest.kt (2)
14-16
: Added imports forJsonObject
andJsonText
.These imports are necessary for the new test method
test_avoid_unnecessary_syncs_in_push_only
to function correctly.
703-771
: New test methodtest_avoid_unecessary_syncs_in_push_only
added.This test method is crucial for ensuring that unnecessary synchronizations are avoided in push-only sync mode. It effectively simulates the scenario and checks the synchronization status and content of the documents to ensure they are as expected. The use of
withTimeout
ensures that the test does not hang indefinitely, which is a good practice for asynchronous tests.
attachment.needRealTimeSync() && | ||
(attachment.document.hasLocalChanges || attachment.remoteChangeEventReceived) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how about moving all the logic to Attachment.needRealTimeSync
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that's much better, I think. done in 6b7ebaf
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
Review Details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (2)
- yorkie/src/main/kotlin/dev/yorkie/core/Attachment.kt (1 hunks)
- yorkie/src/main/kotlin/dev/yorkie/core/Client.kt (1 hunks)
Files skipped from review as they are similar to previous changes (2)
- yorkie/src/main/kotlin/dev/yorkie/core/Attachment.kt
- yorkie/src/main/kotlin/dev/yorkie/core/Client.kt
What this PR does / why we need it?
Any background context you want to provide?
What are the relevant tickets?
Fixes #
Checklist
Summary by CodeRabbit
New Features
Improvements