-
-
Notifications
You must be signed in to change notification settings - Fork 148
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 direction to ListDocuments API #312
Conversation
- To navigate to next and previous pages
Codecov Report
@@ Coverage Diff @@
## main #312 +/- ##
==========================================
+ Coverage 48.07% 48.23% +0.15%
==========================================
Files 59 59
Lines 4903 4918 +15
==========================================
+ Hits 2357 2372 +15
Misses 2285 2285
Partials 261 261
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your contribution. Overall it looks good.
I left some comments.
- To improve the readability of the test code, I clean up as follows:
t.Run("docInfo pagination test", func(t *testing.T) {
localDB, err := memory.New()
assert.NoError(t, err)
assertKeys := func (expectedKeys []string, infos []*db.DocInfo) {
var keys []string
for _, info := range infos {
keys = append(keys, info.CombinedKey)
}
assert.EqualValues(t, expectedKeys, keys)
}
pageSize := 5
totalSize := 9
clientInfo, _ := localDB.ActivateClient(ctx, t.Name())
for i := 0; i < totalSize; i++ {
_, err := localDB.FindDocInfoByKey(ctx, clientInfo, fmt.Sprintf("%d", i), true)
assert.NoError(t, err)
}
// initial page, previousID is empty
infos, err := localDB.FindDocInfosByPreviousIDAndPageSize(ctx, "", pageSize, false)
assert.NoError(t, err)
assertKeys([]string{"8","7","6","5","4"}, infos)
// backward
infos, err = localDB.FindDocInfosByPreviousIDAndPageSize(ctx, infos[len(infos)-1].ID, pageSize, false)
assert.NoError(t, err)
assertKeys([]string{"3","2","1","0"}, infos)
// backward again
emptyInfos, err := localDB.FindDocInfosByPreviousIDAndPageSize(ctx, infos[len(infos)-1].ID, pageSize, false)
assert.NoError(t, err)
assertKeys(nil, emptyInfos)
// forward
infos, err = localDB.FindDocInfosByPreviousIDAndPageSize(ctx, infos[0].ID, pageSize, true)
assert.NoError(t, err)
assertKeys([]string{"4","5","6","7","8"}, infos)
// forward again
emptyInfos, err = localDB.FindDocInfosByPreviousIDAndPageSize(ctx, infos[len(infos)-1].ID, pageSize, true)
assert.NoError(t, err)
assertKeys(nil, emptyInfos)
}
- Does MongoDB work in the same order(from the latest document) as MemoryDB?
- To improve the readability of the test code
@hackerwins Thank you for your comment.
|
What this PR does / why we need it:
Add direction to ListDocuments API to navigate to the next and previous pages.
Which issue(s) this PR fixes:
Address yorkie-team/dashboard#4
Special notes for your reviewer:
Does this PR introduce a user-facing change?:
Additional documentation:
Checklist: