Skip to content

Commit

Permalink
Add conditions for document change updates
Browse files Browse the repository at this point in the history
  • Loading branch information
hackerwins committed Mar 10, 2023
1 parent 2fc95f0 commit 4cb509b
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 14 deletions.
2 changes: 1 addition & 1 deletion client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ func (c *Client) Attach(ctx context.Context, doc *document.Document) error {
if err != nil {
return err
}
// TODO(hackerwins): ChangePack contains the document ID. We need to
// TODO(hackerwins): PbChangePack contains the document ID. We need to
// move the document ID to the ChangePack. But it is not easy because
// of circular dependencies between the pkg/document/change and the api/types.
docID := types.ID(res.ChangePack.DocumentId)
Expand Down
1 change: 0 additions & 1 deletion server/backend/database/mongo/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -864,7 +864,6 @@ func (c *Client) CreateChangeInfos(
"server_seq": docInfo.ServerSeq,
"updated_at": now,
}

if isRemoved {
updateFields["removed_at"] = now
}
Expand Down
4 changes: 2 additions & 2 deletions server/backend/database/mongo/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ func TestClient(t *testing.T) {
assert.Equal(t, info1.ID, info2.ID)
})

t.Run("Set removed_at in docInfo test", func(t *testing.T) {
t.Run("set removed_at in docInfo test", func(t *testing.T) {
docKey := key.Key(fmt.Sprintf("tests$%s", t.Name()))

clientInfo, _ := cli.ActivateClient(ctx, dummyProjectID, t.Name())
Expand All @@ -147,7 +147,7 @@ func TestClient(t *testing.T) {
assert.NotEqual(t, time.Time{}, docInfo.RemovedAt)
})

t.Run("Reuse same key to create docInfo test ", func(t *testing.T) {
t.Run("reuse same key to create docInfo test ", func(t *testing.T) {
docKey := key.Key(fmt.Sprintf("tests$%s", t.Name()))

clientInfo1, _ := cli.ActivateClient(ctx, dummyProjectID, t.Name())
Expand Down
23 changes: 13 additions & 10 deletions server/packs/packs.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ func SnapshotKey(projectID types.ID, docKey key.Key) sync.Key {

// PushPull stores the given changes and returns accumulated changes of the
// given document.
//
// CAUTION(hackerwins, krapie): docInfo's state is constantly mutating as they are
// constantly used as parameters in subsequent subroutines.
func PushPull(
Expand Down Expand Up @@ -85,15 +86,17 @@ func PushPull(
}

// 03. store pushed changes, docInfo and checkpoint of the client to DB.
if err := be.DB.CreateChangeInfos(
ctx,
project.ID,
docInfo,
initialServerSeq,
pushedChanges,
reqPack.IsRemoved,
); err != nil {
return nil, err
if len(pushedChanges) > 0 || reqPack.IsRemoved {
if err := be.DB.CreateChangeInfos(
ctx,
project.ID,
docInfo,
initialServerSeq,
pushedChanges,
reqPack.IsRemoved,
); err != nil {
return nil, err
}
}

if err := be.DB.UpdateClientInfoAfterPushPull(ctx, clientInfo, docInfo); err != nil {
Expand All @@ -116,7 +119,7 @@ func PushPull(
respPack.ApplyDocInfo(docInfo)

// 05. publish document change event then store snapshot asynchronously.
if reqPack.HasChanges() || docInfo.IsRemoved() {
if len(pushedChanges) > 0 || reqPack.IsRemoved {
be.Background.AttachGoroutine(func(ctx context.Context) {
publisherID, err := clientInfo.ID.ToActorID()
if err != nil {
Expand Down

1 comment on commit 4cb509b

@github-actions
Copy link

Choose a reason for hiding this comment

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

Go Benchmark

Benchmark suite Current: 4cb509b Previous: aee5cfd Ratio
BenchmarkDocument/constructor_test 1271 ns/op 752 B/op 12 allocs/op 1715 ns/op 752 B/op 12 allocs/op 0.74
BenchmarkDocument/status_test 670 ns/op 720 B/op 10 allocs/op 945.7 ns/op 720 B/op 10 allocs/op 0.71
BenchmarkDocument/equals_test 9560 ns/op 5072 B/op 85 allocs/op 10483 ns/op 5072 B/op 85 allocs/op 0.91
BenchmarkDocument/nested_update_test 20733 ns/op 11033 B/op 235 allocs/op 45513 ns/op 11033 B/op 235 allocs/op 0.46
BenchmarkDocument/delete_test 27360 ns/op 14161 B/op 310 allocs/op 43889 ns/op 14163 B/op 310 allocs/op 0.62
BenchmarkDocument/object_test 9388 ns/op 5792 B/op 97 allocs/op 14347 ns/op 5792 B/op 97 allocs/op 0.65
BenchmarkDocument/array_test 34017 ns/op 10889 B/op 251 allocs/op 49575 ns/op 10889 B/op 251 allocs/op 0.69
BenchmarkDocument/text_test 37256 ns/op 14058 B/op 456 allocs/op 56477 ns/op 14058 B/op 456 allocs/op 0.66
BenchmarkDocument/text_composition_test 37044 ns/op 17538 B/op 461 allocs/op 57640 ns/op 17538 B/op 461 allocs/op 0.64
BenchmarkDocument/rich_text_test 100455 ns/op 36013 B/op 1108 allocs/op 153935 ns/op 36018 B/op 1108 allocs/op 0.65
BenchmarkDocument/counter_test 19609 ns/op 9057 B/op 212 allocs/op 28259 ns/op 9057 B/op 212 allocs/op 0.69
BenchmarkDocument/text_edit_gc_100 4050939 ns/op 1552667 B/op 17148 allocs/op 5762911 ns/op 1552572 B/op 17147 allocs/op 0.70
BenchmarkDocument/text_edit_gc_1000 322856572 ns/op 136624428 B/op 210630 allocs/op 470217323 ns/op 136648738 B/op 210759 allocs/op 0.69
BenchmarkDocument/text_split_gc_100 4674760 ns/op 2217536 B/op 16576 allocs/op 6457107 ns/op 2217085 B/op 16576 allocs/op 0.72
BenchmarkDocument/text_split_gc_1000 389852169 ns/op 214845096 B/op 211358 allocs/op 552665040 ns/op 214882328 B/op 211533 allocs/op 0.71
BenchmarkDocument/text_delete_all_10000 20202367 ns/op 5903498 B/op 41119 allocs/op 26992781 ns/op 5904120 B/op 41121 allocs/op 0.75
BenchmarkDocument/text_delete_all_100000 261979646 ns/op 53857084 B/op 416033 allocs/op 350749426 ns/op 53822676 B/op 415887 allocs/op 0.75
BenchmarkDocument/text_100 311233 ns/op 117744 B/op 5064 allocs/op 449181 ns/op 117751 B/op 5064 allocs/op 0.69
BenchmarkDocument/text_1000 3383507 ns/op 1152350 B/op 50068 allocs/op 4795250 ns/op 1152384 B/op 50068 allocs/op 0.71
BenchmarkDocument/array_1000 1702403 ns/op 1102011 B/op 11854 allocs/op 2418252 ns/op 1101935 B/op 11853 allocs/op 0.70
BenchmarkDocument/array_10000 20067276 ns/op 9907762 B/op 120712 allocs/op 28456609 ns/op 9907835 B/op 120711 allocs/op 0.71
BenchmarkDocument/array_gc_100 195051 ns/op 97411 B/op 1226 allocs/op 267426 ns/op 97419 B/op 1226 allocs/op 0.73
BenchmarkDocument/array_gc_1000 1958660 ns/op 1169684 B/op 12889 allocs/op 2958902 ns/op 1169613 B/op 12889 allocs/op 0.66
BenchmarkDocument/counter_1000 285465 ns/op 197876 B/op 6490 allocs/op 419936 ns/op 197875 B/op 6490 allocs/op 0.68
BenchmarkDocument/counter_10000 3113055 ns/op 2164801 B/op 69497 allocs/op 4321256 ns/op 2164813 B/op 69497 allocs/op 0.72
BenchmarkDocument/object_1000 1895451 ns/op 1450713 B/op 9902 allocs/op 2749506 ns/op 1450710 B/op 9902 allocs/op 0.69
BenchmarkDocument/object_10000 22348334 ns/op 12368348 B/op 101207 allocs/op 32556405 ns/op 12369933 B/op 101213 allocs/op 0.69
BenchmarkRPC/client_to_server 917806880 ns/op 24788408 B/op 415645 allocs/op 1424898202 ns/op 26022616 B/op 423502 allocs/op 0.64
BenchmarkRPC/client_to_client_via_server 4969608561 ns/op 44501384 B/op 719674 allocs/op 5085859446 ns/op 51599272 B/op 821949 allocs/op 0.98
BenchmarkRPC/attach_large_document 1660173847 ns/op 2133922240 B/op 14844 allocs/op 1945862016 ns/op 2135913704 B/op 14057 allocs/op 0.85
BenchmarkRPC/adminCli_to_server 559861983 ns/op 19085800 B/op 315355 allocs/op 864599752 ns/op 19076676 B/op 315169 allocs/op 0.65
BenchmarkLocker 123.6 ns/op 16 B/op 1 allocs/op 163.3 ns/op 16 B/op 1 allocs/op 0.76
BenchmarkLockerParallel 124.5 ns/op 0 B/op 0 allocs/op 160.5 ns/op 0 B/op 0 allocs/op 0.78
BenchmarkLockerMoreKeys 325.1 ns/op 14 B/op 0 allocs/op 395.9 ns/op 14 B/op 0 allocs/op 0.82
BenchmarkSync/memory_sync_10_test 7114 ns/op 1339 B/op 39 allocs/op 10146 ns/op 1339 B/op 39 allocs/op 0.70
BenchmarkSync/memory_sync_100_test 69575 ns/op 8790 B/op 280 allocs/op 88867 ns/op 8977 B/op 291 allocs/op 0.78
BenchmarkSync/memory_sync_1000_test 690717 ns/op 82166 B/op 2600 allocs/op 851301 ns/op 83403 B/op 2676 allocs/op 0.81
BenchmarkSync/memory_sync_10000_test 7391013 ns/op 856596 B/op 27148 allocs/op 8739772 ns/op 863574 B/op 28081 allocs/op 0.85
BenchmarkSync/etcd_sync_100_test 0.289 ns/op 0 B/op 0 allocs/op 0.4978 ns/op 0 B/op 0 allocs/op 0.58
BenchmarkTextEditing 27744636945 ns/op 8435736176 B/op 19833083 allocs/op 38127137052 ns/op 8436027112 B/op 19835735 allocs/op 0.73

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.