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 RestoreDocument API #303

Closed
wants to merge 2 commits into from
Closed

Add RestoreDocument API #303

wants to merge 2 commits into from

Conversation

hackerwins
Copy link
Member

@hackerwins hackerwins commented Feb 19, 2022

What this PR does / why we need it:

In this PR, I implemented a logic to replace the contents of a document with the previous contents.

The summary logic is as follows:

  1. Create a new change by copying contents from previous changes to restore the document(In the figure below, C5 is created by copying the contents from C2).
  2. After applying the new change(has previous contents), concurrent changes should be rejected from the server. In the figure below, C4' C5' should be rejected.

Screen Shot 2022-03-08 at 3 44 44 PM

The approaches to creating a new change with the previous contents are:

Approach 1: Creating change using snapshot operation

  • Logic:
    • Deepcopy the root element then create a Snapshot Operation with the root element
  • Pros:
    • The size of the change is relatively small. Because it has only one Snapshot Operation.
  • Cons:
    • Conflict can occur if we apply operations created logically before the snapshot.
    • We need to add a new operation called Snapshot Operation.

Approach 2: Creating change using existing operations

  • Logic:
    • Delete all keys from the root object.
    • Create individual editing operations while traversing snapshots
  • Pros
    • Conflict cannot occur even if we apply operations created logically before the snapshot.
    • There is no need to introduce a separate operation.
  • Cons:
    • The size of the change is relatively large and the execution complexity of the application is higher than that of the snapshot.

I implemented the first approach in this PR.

Which issue(s) this PR fixes:

Address #52

Special notes for your reviewer:

Does this PR introduce a user-facing change?:


Additional documentation:


Checklist:

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

@codecov
Copy link

codecov bot commented Feb 19, 2022

Codecov Report

Merging #303 (d0ce917) into main (9e153aa) will decrease coverage by 1.52%.
The diff coverage is 12.26%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #303      +/-   ##
==========================================
- Coverage   48.39%   46.86%   -1.53%     
==========================================
  Files          59       59              
  Lines        4821     4982     +161     
==========================================
+ Hits         2333     2335       +2     
- Misses       2229     2388     +159     
  Partials      259      259              
Impacted Files Coverage Δ
api/converter/to_pb.go 79.18% <0.00%> (-3.38%) ⬇️
client/client.go 9.62% <0.00%> (-0.87%) ⬇️
pkg/document/document.go 43.67% <0.00%> (-13.04%) ⬇️
pkg/document/internal_document.go 20.63% <0.00%> (-0.68%) ⬇️
pkg/document/json/array.go 33.33% <0.00%> (-3.04%) ⬇️
pkg/document/json/counter.go 59.80% <0.00%> (-1.82%) ⬇️
pkg/document/json/object.go 21.05% <0.00%> (-2.48%) ⬇️
pkg/document/json/primitive.go 94.02% <0.00%> (-2.16%) ⬇️
pkg/document/json/rich_text.go 55.55% <0.00%> (-6.95%) ⬇️
pkg/document/json/text.go 43.66% <0.00%> (-7.16%) ⬇️
... and 8 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9e153aa...d0ce917. Read the comment docs.

@hackerwins hackerwins force-pushed the restore-document branch 3 times, most recently from ca97f6c to 0ec940d Compare February 24, 2022 02:18
@hackerwins hackerwins force-pushed the restore-document branch 4 times, most recently from 0f4b410 to bbb219f Compare March 8, 2022 06:42
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