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

Avoid unnecessary syncs in push-only sync mode #188

Merged
merged 3 commits into from
May 29, 2024
Merged

Conversation

7hong13
Copy link
Contributor

@7hong13 7hong13 commented May 29, 2024

What this PR does / why we need it?

Any background context you want to provide?

What are the relevant tickets?

Fixes #

Checklist

  • Added relevant tests or not required
  • Didn't break anything

Summary by CodeRabbit

  • New Features

    • Introduced a new test for synchronization events and text editing operations.
    • Added method to determine real-time synchronization needs in the Attachment class.
  • Improvements

    • Replaced hardcoded timeout value with a reusable constant for better maintainability.
    • Enhanced logic for determining real-time synchronization needs in the Client class.

@7hong13 7hong13 added the enhancement 🌟 New feature or request label May 29, 2024
@7hong13 7hong13 requested review from hackerwins and skhugh May 29, 2024 02:33
@7hong13 7hong13 self-assigned this May 29, 2024
Copy link

coderabbitai bot commented May 29, 2024

Walkthrough

The 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

File Path Change Summary
yorkie/src/androidTest/kotlin/dev/yorkie/core/ClientTest.kt Imported JsonText and JsonObject, added test_avoid_unnecessary_syncs_in_push_only method.
yorkie/src/androidTest/kotlin/dev/yorkie/document/json/JsonTreeConcurrencyTest.kt Replaced hardcoded timeout value with GENERAL_TIMEOUT from dev.yorkie.core.
yorkie/src/main/kotlin/dev/yorkie/core/Attachment.kt Added needRealTimeSync() method to Attachment data class.
yorkie/src/main/kotlin/dev/yorkie/core/Client.kt Modified filterRealTimeSyncNeeded to use Attachment::needRealTimeSync method.

Poem

In code we trust, to sync and test,
With JsonText and objects, we do our best.
Real-time sync, a method now,
To keep our docs in sync somehow.
Timeout constants, unified,
In Yorkie's realm, we're satisfied.
🐇✨


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?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a 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

Commits Files that changed from the base of the PR and between b552be7 and 87773b9.
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 of needRealTimeSync method correctly handles the sync logic based on syncMode. 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 with GENERAL_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 use needRealTimeSync from the Attachment 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 the Attachment class is correctly implemented and checks the syncMode to determine if real-time synchronization is needed. The integration of this method in the filterRealTimeSyncNeeded 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.kt

Length 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.kt

Length 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 for JsonObject and JsonText.

These imports are necessary for the new test method test_avoid_unnecessary_syncs_in_push_only to function correctly.


703-771: New test method test_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.

Comment on lines 185 to 186
attachment.needRealTimeSync() &&
(attachment.document.hasLocalChanges || attachment.remoteChangeEventReceived)
Copy link
Contributor

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?

Copy link
Contributor Author

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

Copy link

@coderabbitai coderabbitai bot left a 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

Commits Files that changed from the base of the PR and between 87773b9 and 6b7ebaf.
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

@7hong13 7hong13 merged commit f2f9550 into main May 29, 2024
4 of 6 checks passed
@7hong13 7hong13 deleted the push_only_sync branch May 29, 2024 05:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement 🌟 New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants