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

Handle local changes correctly when receiving snapshot #868

Merged
merged 1 commit into from
Jul 11, 2024

Conversation

hackerwins
Copy link
Member

@hackerwins hackerwins commented Jul 11, 2024

What this PR does / why we need it?

Handle local changes correctly when receiving snapshot

This commit addresses the issue where unsent local changes were
missing from Document.Root when receiving a snapshot from the server.

To resolve this problem, the local changes are now applied to
Document.Root after applying the snapshot.

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

  • Bug Fixes

    • Ensured local changes are applied correctly as remote changes when a document has a snapshot.
  • Tests

    • Added a test case to verify handling of local changes with snapshots.
    • Adjusted the number of changes over the snapshot threshold in tests for better accuracy.

Copy link

coderabbitai bot commented Jul 11, 2024

Walkthrough

The recent changes improve how the Document class handles local changes when a document has a snapshot. This ensures that local changes are correctly applied as remote changes. Additionally, integration tests have been enhanced to verify the synchronization of local changes and snapshots between clients. A minor adjustment was made to the snapshot test to update 500 changes instead of 700.

Changes

File Change Summary
src/document/document.ts Added condition to apply local changes as remote changes if the document has a snapshot.
test/integration/client_test.ts Introduced test case for handling local changes when receiving a snapshot, verifying synchronization between clients.
test/integration/snapshot_test.ts Modified the loop updating changes over the snapshot threshold by c1 from 700 to 500.

Poem

In code's vast field, a snapshot's grace,
Local changes find their place.
With clients synced and counters bright,
500 beats now mark the night.
Through tests and checks, our code does dance,
In harmony, we take a chance.
🌟🐇✨

Tip

You can customize the tone of the comments in your PRs

Specify the tone of the comments in your PRs by configuring the tone-instructions setting in your project's settings in CodeRabbit.


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.

@hackerwins hackerwins force-pushed the snapshot-with-localchanges branch from a854344 to 6466e1e Compare July 11, 2024 01:50
Copy link

codecov bot commented Jul 11, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 80.81%. Comparing base (1cd4140) to head (6466e1e).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #868   +/-   ##
=======================================
  Coverage   80.80%   80.81%           
=======================================
  Files          60       60           
  Lines        4637     4639    +2     
  Branches      942      943    +1     
=======================================
+ Hits         3747     3749    +2     
  Misses        621      621           
  Partials      269      269           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@hackerwins hackerwins marked this pull request as ready for review July 11, 2024 01:53
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: 1

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 1cd4140 and 6466e1e.

Files selected for processing (3)
  • src/document/document.ts (1 hunks)
  • test/integration/client_test.ts (1 hunks)
  • test/integration/snapshot_test.ts (1 hunks)
Files skipped from review due to trivial changes (1)
  • test/integration/snapshot_test.ts
Additional context used
Biome
test/integration/client_test.ts

[error] 847-847: The assignment should not be in an expression.

The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.

(lint/suspicious/noAssignInExpressions)

Additional comments not posted (2)
test/integration/client_test.ts (1)

842-865: LGTM! Ensure comprehensive test coverage.

The new test case for handling local changes when receiving a snapshot is comprehensive and well-structured.

Ensure that this test is run in various scenarios to validate its robustness.

Tools
Biome

[error] 847-847: The assignment should not be in an expression.

The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.

(lint/suspicious/noAssignInExpressions)

src/document/document.ts (1)

1075-1081: Ensure local changes are applied as remote changes when a snapshot is present.

The new code correctly ensures that local changes are applied as remote changes when a snapshot is present. This logic is crucial for maintaining the integrity of the document's state.

test/integration/client_test.ts Show resolved Hide resolved
@hackerwins hackerwins merged commit c2e0ad5 into main Jul 11, 2024
2 checks passed
@hackerwins hackerwins deleted the snapshot-with-localchanges branch July 11, 2024 07:17
await c1.sync();

// 02. c2 receives the snapshot and increases the counter simultaneously.
c2.sync();
Copy link

@daeyounglnc daeyounglnc Aug 16, 2024

Choose a reason for hiding this comment

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

@hackerwins
Would you explain why this line doesn't use await?

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.

2 participants