Skip to content

Commit

Permalink
Filter out removed documents from ListDocuments API
Browse files Browse the repository at this point in the history
  • Loading branch information
hackerwins committed Jun 28, 2023
1 parent 525cacf commit a2cc85d
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
2 changes: 1 addition & 1 deletion server/backend/database/memory/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -1181,7 +1181,7 @@ func (d *DB) FindDocInfosByPaging(
break
}

if info.ID != paging.Offset {
if info.ID != paging.Offset && info.RemovedAt.IsZero() {
docInfos = append(docInfos, info)
}
}
Expand Down
3 changes: 3 additions & 0 deletions server/backend/database/mongo/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -1200,6 +1200,9 @@ func (c *Client) FindDocInfosByPaging(
"project_id": bson.M{
"$eq": encodedProjectID,
},
"removed_at": bson.M{
"$exists": false,
},
}
if paging.Offset != "" {
encodedOffset, err := encodeID(paging.Offset)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,43 @@ func RunFindDocInfosByPagingTest(t *testing.T, db database.Database, projectID t
})
}
})

t.Run("FindDocInfosByPaging with docInfoRemovedAt test", func(t *testing.T) {
const testDocCnt = 3
ctx := context.Background()

// 01. Initialize a project and create documents.
projectInfo, err := db.CreateProjectInfo(ctx, t.Name(), dummyOwnerID, clientDeactivateThreshold)
assert.NoError(t, err)

var docInfos []*database.DocInfo
for i := 0; i < testDocCnt; i++ {
testDocKey := key.Key("key" + strconv.Itoa(i))
docInfo, err := db.FindDocInfoByKeyAndOwner(ctx, projectInfo.ID, dummyClientID, testDocKey, true)
assert.NoError(t, err)
docInfos = append(docInfos, docInfo)
}

// 02. List the documents.
result, err := db.FindDocInfosByPaging(ctx, projectInfo.ID, types.Paging[types.ID]{
PageSize: 10,
IsForward: false,
})
assert.NoError(t, err)
assert.Len(t, result, len(docInfos))

// 03. Remove a document.
err = db.CreateChangeInfos(ctx, projectInfo.ID, docInfos[0], 0, []*change.Change{}, true)
assert.NoError(t, err)

// 04. List the documents again and check the filtered result.
result, err = db.FindDocInfosByPaging(ctx, projectInfo.ID, types.Paging[types.ID]{
PageSize: 10,
IsForward: false,
})
assert.NoError(t, err)
assert.Len(t, result, len(docInfos)-1)
})
}

// RunCreateChangeInfosTest runs the CreateChangeInfos tests for the given db.
Expand Down

1 comment on commit a2cc85d

@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: a2cc85d Previous: 99ce519 Ratio
BenchmarkDocument/constructor_test 1588 ns/op 752 B/op 12 allocs/op 1271 ns/op 752 B/op 12 allocs/op 1.25
BenchmarkDocument/status_test 845.9 ns/op 720 B/op 10 allocs/op 636.6 ns/op 720 B/op 10 allocs/op 1.33
BenchmarkDocument/equals_test 13575 ns/op 5072 B/op 85 allocs/op 10183 ns/op 5072 B/op 85 allocs/op 1.33
BenchmarkDocument/nested_update_test 31499 ns/op 11033 B/op 235 allocs/op 21228 ns/op 11033 B/op 235 allocs/op 1.48
BenchmarkDocument/delete_test 39804 ns/op 14163 B/op 310 allocs/op 28493 ns/op 14161 B/op 310 allocs/op 1.40
BenchmarkDocument/object_test 12526 ns/op 5792 B/op 97 allocs/op 9969 ns/op 5792 B/op 97 allocs/op 1.26
BenchmarkDocument/array_test 48660 ns/op 10890 B/op 251 allocs/op 35116 ns/op 10889 B/op 251 allocs/op 1.39
BenchmarkDocument/text_test 52533 ns/op 14058 B/op 456 allocs/op 37915 ns/op 14058 B/op 456 allocs/op 1.39
BenchmarkDocument/text_composition_test 55783 ns/op 17538 B/op 461 allocs/op 38517 ns/op 17538 B/op 461 allocs/op 1.45
BenchmarkDocument/rich_text_test 137699 ns/op 36017 B/op 1108 allocs/op 99666 ns/op 36013 B/op 1108 allocs/op 1.38
BenchmarkDocument/counter_test 27639 ns/op 9057 B/op 212 allocs/op 20052 ns/op 9057 B/op 212 allocs/op 1.38
BenchmarkDocument/text_edit_gc_100 5375686 ns/op 1553036 B/op 17151 allocs/op 4015323 ns/op 1552509 B/op 17145 allocs/op 1.34
BenchmarkDocument/text_edit_gc_1000 473312093 ns/op 136649309 B/op 210774 allocs/op 311612329 ns/op 136662792 B/op 210855 allocs/op 1.52
BenchmarkDocument/text_split_gc_100 6057314 ns/op 2217474 B/op 16577 allocs/op 4661020 ns/op 2217054 B/op 16576 allocs/op 1.30
BenchmarkDocument/text_split_gc_1000 523543879 ns/op 214879656 B/op 211516 allocs/op 380981217 ns/op 214875005 B/op 211522 allocs/op 1.37
BenchmarkDocument/text_delete_all_10000 25164957 ns/op 5904051 B/op 41121 allocs/op 16682251 ns/op 5903792 B/op 41120 allocs/op 1.51
BenchmarkDocument/text_delete_all_100000 338104726 ns/op 53840752 B/op 415984 allocs/op 187124319 ns/op 53843445 B/op 416000 allocs/op 1.81
BenchmarkDocument/text_100 426240 ns/op 117749 B/op 5064 allocs/op 307982 ns/op 117746 B/op 5064 allocs/op 1.38
BenchmarkDocument/text_1000 4521656 ns/op 1152376 B/op 50068 allocs/op 3329270 ns/op 1152352 B/op 50068 allocs/op 1.36
BenchmarkDocument/array_1000 2211850 ns/op 1101981 B/op 11854 allocs/op 1735589 ns/op 1102169 B/op 11854 allocs/op 1.27
BenchmarkDocument/array_10000 25768750 ns/op 9907003 B/op 120707 allocs/op 19079153 ns/op 9907061 B/op 120708 allocs/op 1.35
BenchmarkDocument/array_gc_100 225088 ns/op 97413 B/op 1226 allocs/op 180564 ns/op 97398 B/op 1226 allocs/op 1.25
BenchmarkDocument/array_gc_1000 2808982 ns/op 1169757 B/op 12889 allocs/op 1965346 ns/op 1169510 B/op 12889 allocs/op 1.43
BenchmarkDocument/counter_1000 415329 ns/op 197878 B/op 6490 allocs/op 275394 ns/op 197874 B/op 6490 allocs/op 1.51
BenchmarkDocument/counter_10000 4367769 ns/op 2164820 B/op 69497 allocs/op 3007772 ns/op 2164798 B/op 69497 allocs/op 1.45
BenchmarkDocument/object_1000 2751826 ns/op 1450720 B/op 9902 allocs/op 1887695 ns/op 1450581 B/op 9902 allocs/op 1.46
BenchmarkDocument/object_10000 31442602 ns/op 12369071 B/op 101208 allocs/op 21352025 ns/op 12368037 B/op 101202 allocs/op 1.47
BenchmarkRPC/client_to_server 769670406 ns/op 18726692 B/op 300914 allocs/op 431563171 ns/op 18850944 B/op 307073 allocs/op 1.78
BenchmarkRPC/client_to_client_via_server 1240517572 ns/op 30038936 B/op 458638 allocs/op 705610062 ns/op 34897376 B/op 571742 allocs/op 1.76
BenchmarkRPC/attach_large_document 1828654289 ns/op 2164909648 B/op 10635 allocs/op 1514053398 ns/op 2165991600 B/op 9930 allocs/op 1.21
BenchmarkRPC/adminCli_to_server 929612519 ns/op 20405768 B/op 322125 allocs/op 536189742 ns/op 20394964 B/op 322116 allocs/op 1.73
BenchmarkLocker 162.5 ns/op 16 B/op 1 allocs/op 111.9 ns/op 16 B/op 1 allocs/op 1.45
BenchmarkLockerParallel 166.4 ns/op 0 B/op 0 allocs/op 114.8 ns/op 0 B/op 0 allocs/op 1.45
BenchmarkLockerMoreKeys 421.8 ns/op 14 B/op 0 allocs/op 379 ns/op 14 B/op 0 allocs/op 1.11
BenchmarkSync/memory_sync_10_test 10035 ns/op 1340 B/op 39 allocs/op 7217 ns/op 1341 B/op 39 allocs/op 1.39
BenchmarkSync/memory_sync_100_test 86394 ns/op 9016 B/op 294 allocs/op 58777 ns/op 9113 B/op 300 allocs/op 1.47
BenchmarkSync/memory_sync_1000_test 873439 ns/op 83607 B/op 2681 allocs/op 604147 ns/op 83923 B/op 2714 allocs/op 1.45
BenchmarkSync/memory_sync_10000_test 8187569 ns/op 861840 B/op 28118 allocs/op 6303200 ns/op 854103 B/op 27732 allocs/op 1.30
BenchmarkTextEditing 43211149099 ns/op 8436211040 B/op 19835053 allocs/op 24400738928 ns/op 8436518160 B/op 19837008 allocs/op 1.77

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

Please sign in to comment.